diff --git a/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py index f200555b0d46df56c1878900876b18021cbb5a9b..0ec513939f903755473c366b108d4eabafa4aea6 100644 --- a/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py +++ b/SAS/TMSS/services/scheduling/lib/dynamic_scheduling.py @@ -39,6 +39,9 @@ from threading import Thread, Event from lofar.sas.tmss.services.scheduling.constraints import * +# LOFAR needs to have a gap in between observations to (re)initialize hardware. +DEFAULT_INTER_OBSERVATION_GAP = timedelta(seconds=60) + def get_schedulable_scheduling_units() -> [models.SchedulingUnitBlueprint]: '''get a list of all schedulable scheduling_units''' defined_independend_subtasks = models.Subtask.independent_subtasks().filter(state__value='defined') @@ -104,7 +107,7 @@ def schedule_next_scheduling_unit() -> models.SchedulingUnitBlueprint: schedulable_units = get_schedulable_scheduling_units() # estimate the lower_bound_start_time - lower_bound_start_time = get_min_earliest_possible_start_time(schedulable_units, datetime.utcnow() + timedelta(seconds=90)) + lower_bound_start_time = get_min_earliest_possible_start_time(schedulable_units, datetime.utcnow() + DEFAULT_INTER_OBSERVATION_GAP) # estimate the upper_bound_stop_time, which may give us a small timewindow before any next scheduled unit, or a default window of a day try: @@ -189,8 +192,8 @@ def assign_start_stop_times_to_schedulable_scheduling_units(lower_bound_start_ti logger.info("mid-term schedule: next scheduling unit id=%s '%s' start_time=%s", scheduling_unit.id, scheduling_unit.name, start_time) update_subtasks_start_times_for_scheduling_unit(scheduling_unit, start_time) - # keep track of the previous - lower_bound_start_time = scheduling_unit.stop_time + # keep track of the lower_bound_start_time based on last sub.stoptime and gap + lower_bound_start_time = scheduling_unit.stop_time + DEFAULT_INTER_OBSERVATION_GAP scheduling_units.remove(scheduling_unit) else: @@ -251,7 +254,7 @@ class TMSSSchedulingUnitBlueprintDynamicSchedulingMessageHandler(TMSSEventMessag try: logger.info("Updating dynamic schedule....") scheduled_unit = schedule_next_scheduling_unit() - assign_start_stop_times_to_schedulable_scheduling_units(lower_bound_start_time=scheduled_unit.stop_time if scheduled_unit else None) + assign_start_stop_times_to_schedulable_scheduling_units(lower_bound_start_time=scheduled_unit.stop_time+DEFAULT_INTER_OBSERVATION_GAP if scheduled_unit else None) logger.info("Updating dynamic schedule.... finished") except Exception as e: logger.exception(str(e))