From e64887f295f5e8a8aad11ea4c6e1570ff1d428da Mon Sep 17 00:00:00 2001 From: Dana Date: Wed, 2 Aug 2023 17:27:37 +0300 Subject: [PATCH] increase retry delay, include uploads with uploaded state as in progress --- tasks/manual_trigger.py | 5 +++-- tasks/tests/unit/test_manual_trigger.py | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tasks/manual_trigger.py b/tasks/manual_trigger.py index de4268193..3e08de077 100644 --- a/tasks/manual_trigger.py +++ b/tasks/manual_trigger.py @@ -9,6 +9,7 @@ notify_task_name, pulls_task_name, ) +from shared.reports.enums import UploadState from app import celery_app from database.models import Commit, Pull @@ -92,7 +93,7 @@ async def process_async_within_lock( ) still_processing = 0 for upload in uploads: - if not upload.state: + if not upload.state or upload.state_id == UploadState.UPLOADED.db_id: still_processing += 1 if still_processing == 0: self.trigger_notifications(repoid, commitid, commit_yaml) @@ -108,7 +109,7 @@ async def process_async_within_lock( log.info( "Retrying ManualTriggerTask. Some uploads are still being processed." ) - retry_in = 30 + retry_in = 60 * 3**self.request.retries self.retry(max_retries=5, countdown=retry_in) except MaxRetriesExceededError: log.warning( diff --git a/tasks/tests/unit/test_manual_trigger.py b/tasks/tests/unit/test_manual_trigger.py index b658967c4..790d95879 100644 --- a/tasks/tests/unit/test_manual_trigger.py +++ b/tasks/tests/unit/test_manual_trigger.py @@ -1,5 +1,6 @@ import pytest from celery.exceptions import Retry +from shared.reports.enums import UploadState from database.tests.factories import CommitFactory, PullFactory from database.tests.factories.core import UploadFactory @@ -86,9 +87,15 @@ async def test_manual_upload_completion_trigger_uploads_still_processing( celery_app, ) commit = CommitFactory.create() - upload = UploadFactory.create(report__commit=commit, state="") + upload = UploadFactory.create(report__commit=commit, state="", state_id=None) + upload2 = UploadFactory.create( + report__commit=commit, + state="started", + state_id=UploadState.UPLOADED.db_id, + ) dbsession.add(commit) dbsession.add(upload) + dbsession.add(upload2) dbsession.flush() with pytest.raises(Retry): result = await ManualTriggerTask().run_async(