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

TMSS-190: added unschedule methods

parent 4fbfdbf9
No related branches found
No related tags found
1 merge request!252Resolve TMSS-190
...@@ -462,6 +462,39 @@ def schedule_subtask(subtask: Subtask) -> Subtask: ...@@ -462,6 +462,39 @@ def schedule_subtask(subtask: Subtask) -> Subtask:
# ... and re-raise the original exception # ... and re-raise the original exception
raise raise
def unschedule_subtask(subtask: Subtask) -> Subtask:
'''unschedule the given subtask, removing all output dataproducts, and setting its state back to 'defined'.'''
if subtask.state.value != SubtaskState.Choices.SCHEDULED.value:
raise SubtaskSchedulingException("Cannot unschedule subtask id=%d because it is not SCHEDULED. Current state=%s" % (subtask.pk, subtask.state.value))
try:
subtask.state = SubtaskState.objects.get(value=SubtaskState.Choices.UNSCHEDULING.value)
subtask.save()
for output in subtask.outputs.all():
output.dataproducts.all().delete()
#TODO: delete dataproduct transforms
subtask.state = SubtaskState.objects.get(value=SubtaskState.Choices.DEFINED.value)
subtask.save()
except Exception as e:
try:
# set the subtask to state 'ERROR'...
subtask.state = SubtaskState.objects.get(value=SubtaskState.Choices.ERROR.value)
subtask.save()
except Exception as e2:
logger.error(e2)
finally:
# ... and re-raise the original exception
raise
def unschedule_subtasks_in_task_blueprint(task_blueprint: TaskBlueprint):
'''Convenience method: Unschedule (and return) all scheduled subtasks in the task_blueprint'''
scheduled_subtasks = list(task_blueprint.subtasks.filter(state__value=SubtaskState.Choices.SCHEDULED.value).all())
for subtask in scheduled_subtasks:
unschedule_subtask(subtask)
def schedule_subtask_and_update_successor_start_times(subtask: Subtask) -> Subtask: def schedule_subtask_and_update_successor_start_times(subtask: Subtask) -> Subtask:
scheduled_subtask = schedule_subtask(subtask) scheduled_subtask = schedule_subtask(subtask)
shift_successors_until_after_stop_time(scheduled_subtask) shift_successors_until_after_stop_time(scheduled_subtask)
......
from lofar.sas.tmss.tmss.exceptions import * from lofar.sas.tmss.tmss.exceptions import *
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp.models.specification import TaskBlueprint, SchedulingUnitBlueprint, TaskDraft, SchedulingRelationPlacement from lofar.sas.tmss.tmss.tmssapp.models.specification import TaskBlueprint, SchedulingUnitBlueprint, TaskDraft, SchedulingRelationPlacement
from lofar.sas.tmss.tmss.tmssapp.subtasks import create_and_schedule_subtasks_from_task_blueprint from lofar.sas.tmss.tmss.tmssapp.subtasks import create_and_schedule_subtasks_from_task_blueprint, unschedule_subtasks_in_task_blueprint
from lofar.sas.tmss.tmss.tmssapp.models.specification import TaskBlueprint, SchedulingUnitBlueprint from lofar.sas.tmss.tmss.tmssapp.models.specification import TaskBlueprint, SchedulingUnitBlueprint
from lofar.sas.tmss.tmss.tmssapp.subtasks import create_and_schedule_subtasks_from_task_blueprint, create_subtasks_from_task_blueprint, schedule_independent_subtasks_in_task_blueprint from lofar.sas.tmss.tmss.tmssapp.subtasks import create_and_schedule_subtasks_from_task_blueprint, create_subtasks_from_task_blueprint, schedule_independent_subtasks_in_task_blueprint
from lofar.messaging.messagebus import ToBus, DEFAULT_BROKER, DEFAULT_BUSNAME from lofar.messaging.messagebus import ToBus, DEFAULT_BROKER, DEFAULT_BUSNAME
...@@ -286,7 +286,7 @@ def create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_un ...@@ -286,7 +286,7 @@ def create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_un
def schedule_independent_subtasks_in_scheduling_unit_blueprint(scheduling_unit_blueprint: SchedulingUnitBlueprint, start_time: datetime=None) -> models.SchedulingUnitBlueprint: def schedule_independent_subtasks_in_scheduling_unit_blueprint(scheduling_unit_blueprint: SchedulingUnitBlueprint, start_time: datetime=None) -> models.SchedulingUnitBlueprint:
'''Convenience method: Schedule the subtasks in the task_blueprint that are not dependend on predecessors''' '''Convenience method: Schedule the subtasks in the scheduling_unit_blueprint that are not dependend on predecessors'''
task_blueprints = list(scheduling_unit_blueprint.task_blueprints.all()) task_blueprints = list(scheduling_unit_blueprint.task_blueprints.all())
for task_blueprint in task_blueprints: for task_blueprint in task_blueprints:
...@@ -294,3 +294,15 @@ def schedule_independent_subtasks_in_scheduling_unit_blueprint(scheduling_unit_b ...@@ -294,3 +294,15 @@ def schedule_independent_subtasks_in_scheduling_unit_blueprint(scheduling_unit_b
scheduling_unit_blueprint.refresh_from_db() scheduling_unit_blueprint.refresh_from_db()
return scheduling_unit_blueprint return scheduling_unit_blueprint
def unschedule_subtasks_in_scheduling_unit_blueprint(scheduling_unit_blueprint: SchedulingUnitBlueprint) -> models.SchedulingUnitBlueprint:
'''Convenience method: Unschedule all scheduled subtasks in the scheduling_unit_blueprint'''
task_blueprints = list(scheduling_unit_blueprint.task_blueprints.all())
for task_blueprint in task_blueprints:
unschedule_subtasks_in_task_blueprint(task_blueprint)
scheduling_unit_blueprint.refresh_from_db()
return scheduling_unit_blueprint
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