From 763e9b01df5461fb8effe1857f366be42c356182 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 23 Dec 2022 16:16:38 +0100
Subject: [PATCH] TMSS-2227: mark the B-prio schedulable units as not placed
 yet

---
 .../services/scheduling/lib/dynamic_scheduling.py    | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
index 2d342c76308..3cf7383f932 100644
--- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
+++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
@@ -287,7 +287,12 @@ class Scheduler:
             if scheduled_unit:
                 scheduled_units.append(scheduled_unit)
 
-                # can we fit any B-prio units in the new gap(s) in the schedule?
+                # mark the B-prio schedulable units as not placed yet....
+                for scheduling_unit in get_dynamically_schedulable_scheduling_units(priority_queue=models.PriorityQueueType.objects.get(value=models.PriorityQueueType.Choices.B.value)).filter(placed=True):
+                    scheduling_unit.placed = False
+                    scheduling_unit.save()
+
+                # ... and see if we can fit any B-prio units in the new gap(s) in the schedule?
                 scheduled_B_units = self.place_B_priority_units_in_gaps_around_scheduling_unit(scheduled_unit, do_schedule=True)
                 scheduled_units.extend(scheduled_B_units)
 
@@ -568,8 +573,9 @@ class Scheduler:
 
         # mark the schedulable units that they are not 'placed' yet by the scheduler.
         for scheduling_unit in get_dynamically_schedulable_scheduling_units():
-            scheduling_unit.placed = False
-            scheduling_unit.save()
+            if scheduling_unit.placed:
+                scheduling_unit.placed = False
+                scheduling_unit.save()
 
         # use relatively coarser gridders for mid-term schedule. Just to get a rough idea.
         self.search_gridder = Gridder(grid_minutes=3*60)
-- 
GitLab