diff --git a/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py index 5e0bc5ba3cce3190be4a3636bc339348c5ca2f1a..ab8b0d090696b1514572ebc04a7287e56c7870d9 100644 --- a/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py +++ b/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py @@ -35,6 +35,7 @@ from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp.tasks import schedule_independent_subtasks_in_scheduling_unit_blueprint from lofar.sas.tmss.tmss.tmssapp.subtasks import shift_successors_until_after_stop_time from lofar.sas.tmss.client.tmssbuslistener import * +from lofar.sas.tmss.tmss.exceptions import * def schedule_next_scheduling_unit() -> models.SchedulingUnitBlueprint: defined_independend_subtasks = models.Subtask.independent_subtasks().filter(state__value='defined') @@ -48,7 +49,9 @@ def schedule_next_scheduling_unit() -> models.SchedulingUnitBlueprint: remaining_scheduling_units = scheduling_units[1:] # schedule the first one! - scheduled_scheduling_unit = schedule_independent_subtasks_in_scheduling_unit_blueprint(first_scheduling_unit) + # it can start running now + the needed lofar startup time of 1~2 minutes. + start_time = datetime.utcnow() + timedelta(seconds=90) + scheduled_scheduling_unit = schedule_independent_subtasks_in_scheduling_unit_blueprint(first_scheduling_unit, start_time=start_time) # update the starttimes of the remaining ones (so they form queue, and can be visualized in a timeline) prev_scheduling_unit = scheduled_scheduling_unit # keep track of the previous diff --git a/SAS/TMSS/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/src/tmss/tmssapp/subtasks.py index d9970ff6c7dd8680e022b78b1a50acc0e4e7d9d0..e1f0d17a1aebf8d605e117458b489ff98b0e0793 100644 --- a/SAS/TMSS/src/tmss/tmssapp/subtasks.py +++ b/SAS/TMSS/src/tmss/tmssapp/subtasks.py @@ -837,12 +837,14 @@ def create_and_schedule_subtasks_from_task_blueprint(task_blueprint: TaskBluepri return schedule_independent_subtasks_in_task_blueprint(task_blueprint) -def schedule_independent_subtasks_in_task_blueprint(task_blueprint: TaskBlueprint) -> [Subtask]: +def schedule_independent_subtasks_in_task_blueprint(task_blueprint: TaskBlueprint, start_time: datetime=None) -> [Subtask]: '''Convenience method: Schedule (and return) the subtasks in the task_blueprint that are not dependend on any predecessors''' independent_subtasks = list(Subtask.independent_subtasks().filter(task_blueprint_id=task_blueprint.id, state__value=SubtaskState.Choices.DEFINED.value).all()) for subtask in independent_subtasks: - schedule_subtask_and_update_successor_start_times(subtask) + if start_time is not None: + subtask.start_time = start_time + schedule_subtask_and_update_successor_start_times(subtask) return independent_subtasks diff --git a/SAS/TMSS/src/tmss/tmssapp/tasks.py b/SAS/TMSS/src/tmss/tmssapp/tasks.py index ea0272de57483e9b71b9fb42c3592d4eff286eb1..0e5e8eb630a31f883ae945db6a40ad71eb32cbf3 100644 --- a/SAS/TMSS/src/tmss/tmssapp/tasks.py +++ b/SAS/TMSS/src/tmss/tmssapp/tasks.py @@ -285,12 +285,12 @@ def create_task_blueprints_and_subtasks_and_schedule_subtasks_from_scheduling_un return scheduling_unit_blueprint -def schedule_independent_subtasks_in_scheduling_unit_blueprint(scheduling_unit_blueprint: SchedulingUnitBlueprint) -> 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''' task_blueprints = list(scheduling_unit_blueprint.task_blueprints.all()) for task_blueprint in task_blueprints: - schedule_independent_subtasks_in_task_blueprint(task_blueprint) + schedule_independent_subtasks_in_task_blueprint(task_blueprint, start_time=start_time) scheduling_unit_blueprint.refresh_from_db() return scheduling_unit_blueprint