diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py index b9d63c82307d5b0a4d7f379ea0a69d1792a85e02..04197762d27bd4f8c75af8f8c41c3a939f956889 100644 --- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py @@ -132,7 +132,7 @@ def schedule_next_scheduling_unit() -> models.SchedulingUnitBlueprint: def assign_start_stop_times_to_schedulable_scheduling_units(lower_bound_start_time: datetime): '''''' - logger.info("Estimating mid-term schedule...") + logger.info("Estimating mid-term schedule with lower_bound_start_time=%s ..." % lower_bound_start_time) scheduling_units = get_schedulable_scheduling_units() @@ -147,6 +147,9 @@ def assign_start_stop_times_to_schedulable_scheduling_units(lower_bound_start_ti start_time = round_to_second_precision(best_scored_scheduling_unit.start_time) 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) + # TODO check this? + # If the start_time of the subtasks are updated, should the start_time (and stop_time) of the + # scheduling_unit also be updated? Currently its a cached property # 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 diff --git a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py index 1c7559051b0b8d6a28d82982ab3c6138901d6ecf..b2e7129bdee8e90caf55956577179baa94e9f8c4 100755 --- a/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py +++ b/SAS/TMSS/backend/services/scheduling/test/t_dynamic_scheduling.py @@ -136,7 +136,7 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst scheduling_constraints_doc=constraints, scheduling_constraints_template=constraints_template) - @unittest.skip("FIX TEST, skipping it for now") + @unittest.skip("FIX TEST, skipping it for now, see TODO comment in assign_start_stop_times_to_schedulable_scheduling_units") def test_three_simple_observations_no_constraints_different_project_priority(self): scheduling_unit_draft_low = self.create_simple_observation_scheduling_unit("scheduling unit low", scheduling_set=self.scheduling_set_low) scheduling_unit_blueprint_low = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft_low) @@ -179,9 +179,8 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst self.assertGreaterEqual(scheduling_unit_blueprint_medium.start_time - scheduling_unit_blueprint_high.stop_time, DEFAULT_INTER_OBSERVATION_GAP) self.assertGreaterEqual(scheduling_unit_blueprint_low.start_time - scheduling_unit_blueprint_medium.stop_time, DEFAULT_INTER_OBSERVATION_GAP) - @unittest.skip("FIX TEST, skipping it for now") def test_time_bound_unit_wins_even_at_lower_priority(self): - # create two schedunits, one with high one with low prio. + # create two schedule units, one with high one with low prio. # first create them without any further constraints, and check if high prio wins. scheduling_unit_draft_low = self.create_simple_observation_scheduling_unit("scheduling unit low", scheduling_set=self.scheduling_set_low) scheduling_unit_blueprint_low = create_task_blueprints_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft_low) @@ -212,22 +211,23 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst # update the low prio unit. enlarge the time window constraint a bit, so both low and high prio units can fit # this should result that the high prio goes first, and the low prio (which now fits as well) goes second - scheduling_unit_draft_low.scheduling_constraints_doc['time'] = { 'before': (now+scheduling_unit_draft_low.duration+scheduling_unit_draft_high.duration).isoformat()+'Z' } + scheduling_unit_draft_low.scheduling_constraints_doc['time'] = \ + { 'before': (now+scheduling_unit_draft_low.duration+scheduling_unit_draft_high.duration).isoformat()+'Z' } scheduling_unit_draft_low.save() scheduling_unit_blueprint_low.refresh_from_db() # call the method-under-test. best_scored_scheduling_unit = find_best_next_schedulable_unit([scheduling_unit_blueprint_low, scheduling_unit_blueprint_high], now, tomorrow) - # now we expect the scheduling_unit with the lowest project rank to be scheduled first because it can only run within this limited timewindow - self.assertEqual(scheduling_unit_blueprint_high.id, best_scored_scheduling_unit.scheduling_unit.id) + # now we expect the scheduling_unit with the lowest project rank to be scheduled first because it can only + # run within this limited timewindow + self.assertEqual(scheduling_unit_blueprint_low.id, best_scored_scheduling_unit.scheduling_unit.id) # call the method-under-test again but search after first unit (should return low prio unit) stop_time_of_first = best_scored_scheduling_unit.start_time + best_scored_scheduling_unit.scheduling_unit.duration best_scored_scheduling_unit = find_best_next_schedulable_unit([scheduling_unit_blueprint_low, scheduling_unit_blueprint_high], stop_time_of_first, tomorrow) self.assertEqual(scheduling_unit_blueprint_low.id, best_scored_scheduling_unit.scheduling_unit.id) - def test_manual_constraint_is_preventing_scheduling_unit_from_being_scheduled_dynamically(self): scheduling_unit_draft_manual = self.create_simple_observation_scheduling_unit("scheduling unit manual low", scheduling_set=self.scheduling_set_low, constraints={'scheduler': 'manual'}) @@ -244,7 +244,7 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst scheduling_unit_blueprint_manual.refresh_from_db() self.assertEqual(scheduling_unit_blueprint_manual.status, 'schedulable') - @unittest.skip("FIX TEST, skipping it for now") + @unittest.skip("FIX TEST, skipping it for now,...something with manual scheduler ?") def test_manually_scheduled_blocking_dynamically_scheduled(self): scheduling_unit_draft_manual = self.create_simple_observation_scheduling_unit("scheduling unit manual low", scheduling_set=self.scheduling_set_low, constraints={'scheduler': 'manual'}) @@ -260,7 +260,7 @@ class TestDynamicScheduling(TestCase): # Note: we use django.test.TestCase inst # call the method-under-test. scheduled_scheduling_unit = do_dynamic_schedule() - # we expect the no scheduling_unit to be scheduled, because the manual is in the way + # we expect the no scheduling_unit to be scheduled, because the manual is in the way -> Fix it self.assertIsNone(scheduled_scheduling_unit) # check the results