Skip to content

Commit

Permalink
fix: Disable early notify comment (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-codecov authored Oct 31, 2023
1 parent e1d9fb1 commit 6462963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 133 deletions.
47 changes: 4 additions & 43 deletions upload/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,54 +641,15 @@ def dispatch_upload_task(task_arguments, repository, redis):

commitid = task_arguments.get("commit")

upload_sig = TaskService().upload_signature(
TaskService().upload(
repoid=repository.repoid,
commitid=commitid,
report_code=task_arguments.get("report_code"),
# this prevents the results of the notify task (below) from being
# passed as args to this upload task
immutable=True,
countdown=max(
countdown, int(get_config("setup", "upload_processing_delay") or 0)
),
)

# we have a CommitNotifications model for recording if a notification
# has been sent for a particular commit but we'd like this early notification
# (below) to only happen once for a PR. Checking the `commentid` isn't strictly
# correct but works for now since the early notify is only for PR comments.

notified = False
commit = Commit.objects.filter(commitid=commitid).first()
if commit and commit.pullid is not None:
pull = Pull.objects.filter(
repository_id=commit.repository_id, pullid=commit.pullid
).first()
if pull and pull.commentid:
notified = True

if notified:
# we've already notified on this commit - just process
# the upload
upload_sig.apply_async(
countdown=max(
countdown, int(get_config("setup", "upload_processing_delay") or 0)
),
)
else:
# we have not notified yet
#
# notify early with a "processing" indicator and then
# start processing the upload
TaskService().notify_signature(
repoid=repository.repoid,
commitid=task_arguments.get("commit"),
empty_upload="processing",
).apply_async(
link=upload_sig.set(
countdown=max(
countdown, int(get_config("setup", "upload_processing_delay") or 0)
),
)
)


def validate_activated_repo(repository):
if repository.active and not repository.activated:
Expand Down
94 changes: 4 additions & 90 deletions upload/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,44 +873,9 @@ def test_validate_upload_valid_upload_repo_activated(self):
assert repo.active == True
assert repo.deleted == False

@patch("services.task.TaskService.notify_signature")
@patch("services.task.TaskService.upload_signature")
def test_dispatch_upload_task_signatures(
self, mock_task_service_upload, mock_task_service_notify
):
repo = G(Repository)
task_arguments = {
"commit": "commit123",
"version": "v4",
"report_code": "local_report",
}

expected_key = f"uploads/{repo.repoid}/commit123"

redis = MockRedis(
expected_task_key=expected_key,
expected_task_arguments=task_arguments,
expected_expire_time=86400,
)

dispatch_upload_task(task_arguments, repo, redis)
assert mock_task_service_notify.called
mock_task_service_notify.assert_called_with(
repoid=repo.repoid,
commitid=task_arguments.get("commit"),
empty_upload="processing",
)
assert mock_task_service_upload.called
mock_task_service_upload.assert_called_with(
repoid=repo.repoid,
commitid=task_arguments.get("commit"),
report_code="local_report",
immutable=True,
)

@freeze_time("2023-01-01T00:00:00")
@patch("celery.canvas.Signature.apply_async")
def test_dispatch_upload_task_apply_async(self, apply_async):
@patch("services.task.TaskService.upload")
def test_dispatch_upload_task(self, upload):
repo = G(Repository)
task_arguments = {
"commit": "commit123",
Expand All @@ -927,62 +892,11 @@ def test_dispatch_upload_task_apply_async(self, apply_async):
)

dispatch_upload_task(task_arguments, repo, redis)
apply_async.assert_called_once_with(
link={
"task": "app.tasks.upload.Upload",
"args": (),
"kwargs": {
"repoid": repo.repoid,
"commitid": "commit123",
"report_code": "local_report",
"debug": False,
"rebuild": False,
},
"options": {
"queue": "uploads",
"headers": {"created_timestamp": "2023-01-01T00:00:00"},
"time_limit": None,
"soft_time_limit": None,
"countdown": 4,
},
"subtask_type": None,
"immutable": True,
}
)

@patch("services.task.TaskService.notify_signature")
@patch("services.task.TaskService.upload_signature")
def test_dispatch_upload_task_already_notified(
self,
mock_task_service_upload,
mock_task_service_notify,
):
repo = G(Repository)
pull = PullFactory(repository=repo, commentid="something")
commit = CommitFactory(repository=repo, author=repo.author, pullid=pull.pullid)
task_arguments = {
"commit": commit.commitid,
"version": "v4",
"report_code": "local_report",
}

expected_key = f"uploads/{repo.repoid}/{commit.commitid}"

redis = MockRedis(
expected_task_key=expected_key,
expected_task_arguments=task_arguments,
expected_expire_time=86400,
)

dispatch_upload_task(task_arguments, repo, redis)

assert not mock_task_service_notify.called
mock_task_service_upload.assert_called_once()
mock_task_service_upload.assert_called_with(
upload.assert_called_once_with(
repoid=repo.repoid,
commitid=task_arguments.get("commit"),
report_code="local_report",
immutable=True,
countdown=4,
)


Expand Down

0 comments on commit 6462963

Please sign in to comment.