Skip to content
Snippets Groups Projects
Commit 31e36590 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-745: handle trigger submission in one transaction. If anything fails, the...

TMSS-745: handle trigger submission in one transaction. If anything fails, the whole trigger is discarded.
parent 428099d0
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!504TMSS-745: Responsive Telescope,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
......@@ -372,22 +372,24 @@ def submit_trigger(request):
logger.error(msg)
return RestResponse(msg, status=status.HTTP_403_FORBIDDEN)
# try to create the draft from the trigger_doc
scheduling_unit_draft = create_scheduling_unit_draft_from_observing_strategy_template(strategy_template,
scheduling_set,
name=trigger_doc['name'],
description=trigger_doc.get('description'),
requirements_doc_overrides=trigger_doc['scheduling_unit_observing_strategy_template'].get('overrides', {}))
# indicate that we are allowed to interrupt the telescope
scheduling_unit_draft.interrupts_telescope = True
scheduling_unit_draft.save()
# if the trigger mode is 'run', then turn it into a blueprint which the dynamic scheduler will try to pick up, given the scheduling constraints
if trigger_doc['mode'].lower() == 'run':
scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft)
return RestResponse(SchedulingUnitBlueprintSerializer(scheduling_unit_blueprint, context={'request': request}).data,
from django.db import transaction
with transaction.atomic():
# try to create the draft from the trigger_doc
scheduling_unit_draft = create_scheduling_unit_draft_from_observing_strategy_template(strategy_template,
scheduling_set,
name=trigger_doc['name'],
description=trigger_doc.get('description'),
requirements_doc_overrides=trigger_doc['scheduling_unit_observing_strategy_template'].get('overrides', {}))
# indicate that we are allowed to interrupt the telescope
scheduling_unit_draft.interrupts_telescope = True
scheduling_unit_draft.save()
# if the trigger mode is 'run', then turn it into a blueprint which the dynamic scheduler will try to pick up, given the scheduling constraints
if trigger_doc['mode'].lower() == 'run':
scheduling_unit_blueprint = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft)
return RestResponse(SchedulingUnitBlueprintSerializer(scheduling_unit_blueprint, context={'request': request}).data,
status=status.HTTP_201_CREATED)
return RestResponse(SchedulingUnitDraftSerializer(scheduling_unit_draft, context={'request': request}).data,
status=status.HTTP_201_CREATED)
return RestResponse(SchedulingUnitDraftSerializer(scheduling_unit_draft, context={'request': request}).data,
status=status.HTTP_201_CREATED)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment