diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py index 7b1d1931bb25ca1dc9921429c3171b077d2afef9..d8d6d2cfa8770d386d653b2a5ce683ecf86b50cc 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py @@ -45,35 +45,35 @@ def check_prerequities_for_subtask_creation(task_blueprint: TaskBlueprint) -> bo def create_subtasks_from_task_blueprint(task_blueprint: TaskBlueprint) -> [Subtask]: '''Generic create-method for subtasks. Calls the appropriate create method based on the task_blueprint specifications_template name.''' - logger.debug("creating subtask(s) from task_blueprint id=%s name='%s' type='%s' scheduling_unit_blueprint id=%s", - task_blueprint.id, task_blueprint.name, task_blueprint.specifications_template.type.value, - task_blueprint.scheduling_unit_blueprint.id) - check_prerequities_for_subtask_creation(task_blueprint) + with transaction.atomic(): + logger.debug("creating subtask(s) from task_blueprint id=%s name='%s' type='%s' scheduling_unit_blueprint id=%s", + task_blueprint.id, task_blueprint.name, task_blueprint.specifications_template.type.value, + task_blueprint.scheduling_unit_blueprint.id) + check_prerequities_for_subtask_creation(task_blueprint) - subtasks = [] - - # recurse over predecessors, so that all dependencies in predecessor subtasks can be met. - for predecessor in task_blueprint.predecessors.all(): - subtasks.extend(create_subtasks_from_task_blueprint(predecessor)) - - if task_blueprint.subtasks.count() > 0: - logger.debug("skipping creation of subtasks because they already exist for task_blueprint id=%s, name='%s', task_template_name='%s'", - task_blueprint.id, task_blueprint.name, task_blueprint.specifications_template.name) - return subtasks - - # fixed mapping from template name to generator functions which create the list of subtask(s) for this task_blueprint - generators_mapping = {'target observation': [create_observation_control_subtask_from_task_blueprint, - create_qafile_subtask_from_task_blueprint, - create_qaplots_subtask_from_task_blueprint], - 'preprocessing pipeline': [create_preprocessing_subtask_from_task_blueprint], - 'pulsar pipeline': [create_pulsar_pipeline_subtask_from_task_blueprint], - 'ingest': [create_ingest_subtask_from_task_blueprint], - 'cleanup': [create_cleanup_subtask_from_task_blueprint]} - generators_mapping['calibrator observation'] = generators_mapping['target observation'] - generators_mapping['parallel calibrator target observation'] = generators_mapping['target observation'] - generators_mapping['beamforming observation'] = [create_observation_control_subtask_from_task_blueprint] + subtasks = [] + + # recurse over predecessors, so that all dependencies in predecessor subtasks can be met. + for predecessor in task_blueprint.predecessors.all(): + subtasks.extend(create_subtasks_from_task_blueprint(predecessor)) + + if task_blueprint.subtasks.count() > 0: + logger.debug("skipping creation of subtasks because they already exist for task_blueprint id=%s, name='%s', task_template_name='%s'", + task_blueprint.id, task_blueprint.name, task_blueprint.specifications_template.name) + return subtasks + + # fixed mapping from template name to generator functions which create the list of subtask(s) for this task_blueprint + generators_mapping = {'target observation': [create_observation_control_subtask_from_task_blueprint, + create_qafile_subtask_from_task_blueprint, + create_qaplots_subtask_from_task_blueprint], + 'preprocessing pipeline': [create_preprocessing_subtask_from_task_blueprint], + 'pulsar pipeline': [create_pulsar_pipeline_subtask_from_task_blueprint], + 'ingest': [create_ingest_subtask_from_task_blueprint], + 'cleanup': [create_cleanup_subtask_from_task_blueprint]} + generators_mapping['calibrator observation'] = generators_mapping['target observation'] + generators_mapping['parallel calibrator target observation'] = generators_mapping['target observation'] + generators_mapping['beamforming observation'] = [create_observation_control_subtask_from_task_blueprint] - with transaction.atomic(): template_name = task_blueprint.specifications_template.name if template_name in generators_mapping: generators = generators_mapping[template_name] diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py index bf5c3153e2541c2c2ae707f8621687965d755bcd..c7bbc891a3d66e79122a45c4a77e9c5f3466e3e8 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/tasks.py @@ -426,8 +426,9 @@ def create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit def create_task_blueprint_and_subtasks_from_task_draft(task_draft: models.TaskDraft) -> models.TaskBlueprint: '''Convenience method: Create the task_blueprint, then create the task_blueprint's subtasks, and schedule the ones that are not dependend on predecessors''' - task_blueprint = create_task_blueprint_from_task_draft(task_draft) - create_subtasks_from_task_blueprint(task_blueprint) + with transaction.atomic(): + task_blueprint = create_task_blueprint_from_task_draft(task_draft) + create_subtasks_from_task_blueprint(task_blueprint) task_blueprint.refresh_from_db() return task_blueprint @@ -457,14 +458,15 @@ def update_task_blueprint_graph_from_draft(scheduling_unit_blueprint: models.Sch def update_task_blueprints_and_subtasks_graph_from_draft(scheduling_unit_blueprint: models.SchedulingUnitBlueprint) -> models.SchedulingUnitBlueprint: '''Convenience method: Create the scheduling_unit_blueprint's task_blueprint(s), then create each task_blueprint's subtasks''' - scheduling_unit_blueprint = update_task_blueprint_graph_from_draft(scheduling_unit_blueprint) + with transaction.atomic(): + scheduling_unit_blueprint = update_task_blueprint_graph_from_draft(scheduling_unit_blueprint) - for task_blueprint in scheduling_unit_blueprint.task_blueprints.all(): - create_subtasks_from_task_blueprint(task_blueprint) + for task_blueprint in scheduling_unit_blueprint.task_blueprints.all(): + create_subtasks_from_task_blueprint(task_blueprint) - # assign reasonable default start/stop times so the subtasks/tasks/sched_unit can be displayed in a timeline view - # these default start/stop times can of course be overridden by the operator and/or dynamic scheduling. - update_subtasks_start_times_for_scheduling_unit(scheduling_unit_blueprint, round_to_minute_precision(datetime.utcnow()+timedelta(hours=1))) + # assign reasonable default start/stop times so the subtasks/tasks/sched_unit can be displayed in a timeline view + # these default start/stop times can of course be overridden by the operator and/or dynamic scheduling. + update_subtasks_start_times_for_scheduling_unit(scheduling_unit_blueprint, round_to_minute_precision(datetime.utcnow()+timedelta(hours=1))) # refresh so all related fields are updated. scheduling_unit_blueprint.refresh_from_db()