Skip to content

Commit

Permalink
Don't show when task will be retried (it is not real)
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack authored Jul 15, 2024
1 parent 23985f1 commit b0f99d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
16 changes: 4 additions & 12 deletions adit/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from time import sleep
from typing import cast

import humanize
import pglock
from adit_radis_shared.accounts.models import User
from django import db
Expand Down Expand Up @@ -80,6 +79,8 @@ def broadcast_mail(subject: str, message: str):
),
)
def process_dicom_task(context: JobContext, model_label: str, task_id: int):
assert context.job

dicom_task = get_dicom_task(model_label, task_id)
assert dicom_task.status == DicomTask.Status.PENDING

Expand Down Expand Up @@ -135,22 +136,13 @@ def _monitor_task(context: JobContext, future: ProcessFuture) -> None:
# Cave, the the attempts of the Procrastinate job must not be the same number
# as the attempts of the DicomTask. The DicomTask could be started by multiple
# Procrastinate jobs (e.g. if the user canceled and resumed the same task).
assert context.job
job_attempts = context.job.attempts
delta = settings.DICOM_TASK_EXPONENTIAL_WAIT ** (job_attempts + 1)
humanized_delta = humanize.naturaldelta(delta)

if job_attempts < settings.DICOM_TASK_RETRIES:
logger.info(f"Retrying {dicom_task} in {humanized_delta}.")

if context.job.attempts < settings.DICOM_TASK_RETRIES:
dicom_task.status = DicomTask.Status.PENDING
dicom_task.message = f"Task failed, but will be retried in {humanized_delta}."
dicom_task.message = "Task failed, but will be retried."
if dicom_task.log:
dicom_task.log += "\n"
dicom_task.log += str(err)
else:
logger.error("No more retries for finally failed %s: %s", dicom_task, str(err))

dicom_task.status = DicomTask.Status.FAILURE
dicom_task.message = str(err)

Expand Down
2 changes: 1 addition & 1 deletion adit/core/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def process(self):
dicom_task.refresh_from_db()
assert dicom_task.queued_job is not None
assert dicom_task.status == DicomTask.Status.PENDING
assert dicom_task.message == "Task failed, but will be retried in 10 seconds."
assert dicom_task.message == "Task failed, but will be retried."
assert dicom_task.attempts == 1


Expand Down

0 comments on commit b0f99d5

Please sign in to comment.