From 95fb7924f08aa9a9ae4c091dc21f94a350209a6d Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 23 Dec 2022 15:59:07 +0100
Subject: [PATCH] TMSS-2227: (and TMSS-2122) use 'placed' flag to determine
 which B-units to place in the gaps

---
 .../backend/services/scheduling/lib/dynamic_scheduling.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
index c431ef05934..2d342c76308 100644
--- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
+++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
@@ -531,7 +531,7 @@ class Scheduler:
         '''try to schedule one or more scheduling units from queue B in the gap between the given scheduled_unit and its previous observed+ unit'''
         placed_units = []
 
-        schedulable_units_queue_B = get_dynamically_schedulable_scheduling_units(priority_queue=models.PriorityQueueType.objects.get(value=models.PriorityQueueType.Choices.B.value)).exclude(id=scheduling_unit.id)
+        schedulable_units_queue_B = get_dynamically_schedulable_scheduling_units(priority_queue=models.PriorityQueueType.objects.get(value=models.PriorityQueueType.Choices.B.value)).exclude(id=scheduling_unit.id).filter(placed=False)
         if not schedulable_units_queue_B.exists():
             return placed_units
 
@@ -557,10 +557,8 @@ class Scheduler:
 
                 placed_units.append(best_B_candidate_for_gap.scheduling_unit)
 
-                # TODO: at this moment we have no means to distinguish between a placed and an unplaced schedulable (B) unit. When we can make that distinction, remove the "if do_schedule" below, and always recurse.
-                if do_schedule:
-                    # Recurse. There may be a new gap, so let's try to squeeze in more.
-                    placed_units.extend(self.place_B_priority_units_in_gaps_around_scheduling_unit(best_B_candidate_for_gap.scheduling_unit, do_schedule=do_schedule))
+                # Recurse. There may be a new gap, so let's try to squeeze in more.
+                placed_units.extend(self.place_B_priority_units_in_gaps_around_scheduling_unit(best_B_candidate_for_gap.scheduling_unit, do_schedule=do_schedule))
 
         return placed_units
 
-- 
GitLab