From 7ed3fe8f467eca7f17241202a4fa6b9f2e7716f1 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 30 Nov 2023 11:27:34 +0100
Subject: [PATCH] TMSS-2836: schedule new related units right away

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

diff --git a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
index 1aceae9d986..9c0957cd494 100644
--- a/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
+++ b/SAS/TMSS/backend/services/scheduling/lib/dynamic_scheduling.py
@@ -1047,6 +1047,15 @@ class TMSSDynamicSchedulingMessageHandler(TMSSEventMessageHandler):
         if scheduling_unit.project.project_state.value != models.ProjectState.Choices.ACTIVE.value:
             mark_independent_subtasks_in_scheduling_unit_blueprint_as_unschedulable(scheduling_unit, reason="project is not active")
 
+        try:
+            # if this is a new unit, and it is related to another one, then scheduling it right away.
+            if scheduling_unit_blueprint.scheduling_constraints_template.name == "relational":
+                related_unit_id = scheduling_unit_blueprint.scheduling_constraints_doc.get('other', -1)
+                related_unit = models.SchedulingUnitBlueprint.objects.get(id=related_unit_id)
+                self.scheduler.try_schedule_relational_units(related_unit)
+        except Exception as e:
+            logger.error(str(e))
+
         # trigger next schedule computation
         self.scheduler.trigger()
 
-- 
GitLab