diff --git a/SAS/TMSS/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/src/tmss/tmssapp/subtasks.py index e87ba8bd7e29b711368b3c5962cf2d8c57052f77..3fc6331628d3a50b3ef4945ddf1aa89e9a0286c7 100644 --- a/SAS/TMSS/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/src/tmss/tmssapp/subtasks.py @@ -33,6 +33,7 @@ def create_subtasks_from_task_blueprint(task_blueprint: TaskBlueprint) -> [Subta create_qaplots_subtask_from_task_blueprint], 'calibrator schema': [create_observation_control_subtask_from_task_blueprint_calibrator_observation, # skip QA for now..can not handle multiple qa plots subtasks + # also use related task blueprint setting in case of calibrator #create_qafile_subtask_from_task_blueprint, #create_qaplots_subtask_from_task_blueprint ], @@ -143,13 +144,14 @@ def create_observation_control_subtask_from_task_blueprint_calibrator_observatio """ logger.info("Task (id=%d) is a Calibrator Addon Observation" % task_blueprint.pk) # Get the related Target Observation Task - # TODO: - # 1) The TaskSchedulingRelationDraft should be copied to TaskSchedulingRelationBlueprint during create blueprint - # 2) Get the related blueprint_task, which should be a Target Observation - # Somehow I can not retrieve it with ......objects.get(first="Calibrator Observation 1") ...??? - related_blueprint_target_observation = TaskBlueprint.objects.get(name="Task Blueprint of Target Observation") - calibrator_add_on_spec = task_blueprint.specifications_doc + related_blueprint_target_observation = get_related_scheduling_blueprint_task(task_blueprint) + if related_blueprint_target_observation is None: + raise SubtaskCreationException('Cannot create observation control subtasks for task id=%s because no related scheduling blueprint task exists.' + ' This is required for a calibrator observation' % task_blueprint.pk) + else: + logger.info("Related scheduling blueprint task found id=%d", related_blueprint_target_observation.pk) + calibrator_add_on_spec = task_blueprint.specifications_doc subtask_specifications_doc = get_station_specifications_from_observation_blueprint(related_blueprint_target_observation.specifications_doc) # Retrieve pointings from the original calibrator AddOn specifications subtask_specifications_doc["stations"]["analog_pointing"] = { @@ -165,6 +167,26 @@ def create_observation_control_subtask_from_task_blueprint_calibrator_observatio return subtask +def get_related_scheduling_blueprint_task(task_blueprint): + """ + Retrieve the related scheduling blueprint task object + if nothing found return None + :param task_blueprint: + :return: related_scheduling_task_blueprint + """ + related_scheduling_task_blueprint = None + try: + related_scheduling = TaskSchedulingRelationBlueprint.objects.get(first=task_blueprint) + related_scheduling_task_blueprint = related_scheduling.second + except TaskRelationBlueprint.DoesNotExist: + try: + related_scheduling = TaskSchedulingRelationBlueprint.objects.get(second=task_blueprint) + related_scheduling_task_blueprint = related_scheduling.first + except TaskRelationBlueprint.DoesNotExist: + logger.info("No related scheduling blueprint task found for id=%d", task_blueprint.pk) + return related_scheduling_task_blueprint + + def create_observation_control_subtask_from_task_blueprint(task_blueprint: TaskBlueprint, extra_specifications_doc) -> Subtask: """ Create an observation control subtask . @@ -271,6 +293,7 @@ def create_qafile_subtask_from_observation_subtask(observation_subtask: Subtask) # done, now return the subtask, and allow the system to wait for the predecessors to be finished before we schedule this qa_file_subtask return qafile_subtask + def create_qaplots_subtask_from_task_blueprint(task_blueprint: TaskBlueprint) -> Subtask: qafile_subtasks = [st for st in task_blueprint.subtasks.all() if st.specifications_template.type.value == SubtaskType.Choices.QA_FILES.value] if qafile_subtasks: