From e4e22ef60864ffd68b77df438df76306452bb96d Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 26 Oct 2021 08:02:37 +0200 Subject: [PATCH] TMSS-1124: schedule within a transaction, rolling back upon exception --- SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py index 68f849f77d1..2d230fd4e14 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py @@ -951,26 +951,27 @@ def schedule_subtask(subtask: Subtask) -> Subtask: subtask.save() try: - if subtask.specifications_template.type.value == SubtaskType.Choices.PIPELINE.value: - return schedule_pipeline_subtask(subtask) + with transaction.atomic(): + if subtask.specifications_template.type.value == SubtaskType.Choices.PIPELINE.value: + return schedule_pipeline_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.OBSERVATION.value: - return schedule_observation_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.OBSERVATION.value: + return schedule_observation_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.QA_FILES.value: - return schedule_qafile_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.QA_FILES.value: + return schedule_qafile_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.QA_PLOTS.value: - return schedule_qaplots_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.QA_PLOTS.value: + return schedule_qaplots_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.INGEST.value: - return schedule_ingest_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.INGEST.value: + return schedule_ingest_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.CLEANUP.value: - return schedule_cleanup_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.CLEANUP.value: + return schedule_cleanup_subtask(subtask) - if subtask.specifications_template.type.value == SubtaskType.Choices.COPY.value: - return schedule_copy_subtask(subtask) + if subtask.specifications_template.type.value == SubtaskType.Choices.COPY.value: + return schedule_copy_subtask(subtask) raise SubtaskSchedulingException("Cannot schedule subtask id=%d because there is no schedule-method known for this subtasktype=%s." % (subtask.pk, subtask.specifications_template.type.value)) -- GitLab