Skip to content

Commit

Permalink
Skip canceled tasks of tasks of canceled jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Nov 7, 2023
1 parent 0ac2448 commit 3794b9f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions adit/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,25 @@ def run(self, task_id: int):
def process_dicom_task(
self, dicom_task: DicomTask
) -> tuple[DicomTask.Status, str, list[DicomLogEntry]]:
logger.info("%s started.", dicom_task)

dicom_job = dicom_task.job

# Dicom jobs are canceled by the DicomJobCancelView and tasks are also revoked there,
# but it could happen that the task was already picked up by a worker. We then just
# ignore that task.
# but it could happen that the task was already picked up by a worker or under rare
# circumstances will nevertheless get picked up by a worker (e.g. the worker crashes
# and forgot its revoked tasks). We then just ignore that task.
if (
dicom_job.status == DicomJob.Status.CANCELING
or dicom_task.status == DicomTask.Status.CANCELED
dicom_task.status == DicomTask.Status.CANCELED
or dicom_job.status == DicomJob.Status.CANCELED
or dicom_job.status == DicomJob.Status.CANCELING
):
logger.debug(f"{dicom_task} cancelled.")
return (DicomTask.Status.CANCELED, "Task was canceled.", [])

if dicom_task.status != dicom_task.Status.PENDING:
raise AssertionError(f"Invalid {dicom_task} status: {dicom_task.get_status_display()}")

logger.info("%s started.", dicom_task)

app_settings = self.app_settings_class.get()
assert app_settings

Expand Down

0 comments on commit 3794b9f

Please sign in to comment.