diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py index 0646b911c619b72ae5b20c8faf6bffb0e5bf927c..f3ba537af21c9dd8c54e1eaac39f9190f42112a7 100644 --- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py @@ -261,7 +261,7 @@ class Scheduler: if isinstance(e, SchedulerInterruptedException): # Scheduler was interrupted, re-raise and let the scheduling loop handle it raise - elif isinstance(e, SubtaskSchedulingException): + elif isinstance(e, SubtaskSchedulingException) or isinstance(e, SchedulingUnitSchedulingException): logger.warning("Could not schedule fixed_time-scheduled scheduling unit id=%d: %s", schedulable_unit.id, e) else: logger.exception("Could not schedule fixed_time-scheduled scheduling unit id=%d: %s", schedulable_unit.id, e) @@ -714,7 +714,7 @@ class Scheduler: # check if unit has any schedulable independent subtask if not scheduling_unit.subtasks.filter(inputs=None).filter(obsolete_since__isnull=True).exists(): - raise SchedulingException("scheduling_unit id=%s has no independent schedulable subtask(s) and thus cannot be scheduled" % (scheduling_unit.id, )) + raise SchedulingUnitSchedulingException("scheduling_unit id=%s has no independent schedulable subtask(s) and thus cannot be scheduled" % (scheduling_unit.id, )) # check if unit is schedulable if scheduling_unit.status.value != models.SchedulingUnitStatus.Choices.SCHEDULABLE.value: @@ -722,7 +722,12 @@ class Scheduler: scheduling_unit = unschededule_previously_scheduled_unit_if_needed_and_possible(scheduling_unit, start_time) # check again if unit is schedulable if scheduling_unit is not None and scheduling_unit.status.value != models.SchedulingUnitStatus.Choices.SCHEDULABLE.value: - raise SchedulingException("scheduling_unit id=%s cannot be scheduled with status='%s'" % (scheduling_unit.id, scheduling_unit.status.value)) + raise SchedulingUnitSchedulingException("scheduling_unit id=%s cannot be scheduled with status='%s'" % (scheduling_unit.id, scheduling_unit.status.value)) + + # check if start_time in the future + lower_start_bound = round_to_second_precision(datetime.utcnow() + DEFAULT_NEXT_STARTTIME_GAP - timedelta(seconds=10)) # 10sec extra margin + if start_time < lower_start_bound: + raise SchedulingUnitSchedulingException("scheduling_unit id=%s cannot be scheduled at '%s' before now+startup='%s' " % (scheduling_unit.id, start_time, lower_start_bound)) # cancel and/or unschedule current units-in-the-way... # (only if possible, depending on priorities and other rules...) diff --git a/SAS/TMSS/backend/src/tmss/exceptions.py b/SAS/TMSS/backend/src/tmss/exceptions.py index b9fb105b1420f9a3d81ab867283e9029954dfcae..6b5051189e7ce6befc022a68d7ceae50c297d42d 100644 --- a/SAS/TMSS/backend/src/tmss/exceptions.py +++ b/SAS/TMSS/backend/src/tmss/exceptions.py @@ -41,6 +41,9 @@ class SchedulingException(TMSSException): class SchedulerInterruptedException(SchedulingException): pass +class SchedulingUnitSchedulingException(SchedulingException): + pass + class SubtaskSchedulingException(SubtaskException, SchedulingException): pass