From adef8c41e5b1e567a17045d1af0c597e5e78c206 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rn=20K=C3=BCnsem=C3=B6ller?=
 <jkuensem@physik.uni-bielefeld.de>
Date: Thu, 16 Sep 2021 18:14:07 +0200
Subject: [PATCH] TMSS-877: Leave subtask in FINISHING state in case feedback
 is overdue

---
 .../services/feedback_handling/lib/feedback_handling.py  | 9 +++------
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py            | 2 +-
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py b/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py
index bbff5b48f2c..a465e6c17d3 100644
--- a/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py
+++ b/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py
@@ -120,16 +120,13 @@ class HybridFeedbackMessageHandler(TMSSEventMessageHandler):
     def before_receive_message(self):
         # use TMSSEventMessageHandler template pattern to act perform extra business logic in the loop
         self._read_feedback_message_and_process(1)
-        self._set_subtask_status_to_cancelled_upon_feedback_timeout()
+        self._detect_and_log_feedback_timeout()
         super().before_receive_message()
 
-    def _set_subtask_status_to_cancelled_upon_feedback_timeout(self):
+    def _detect_and_log_feedback_timeout(self):
         for subtask_id, wait_timeout_timestamp in list(self._finishing_subtasks.items()):
             if datetime.utcnow() > wait_timeout_timestamp:
-                del self._finishing_subtasks[subtask_id]
-                logger.warning('cancelling subtask id=%s due to timeout of %s seconds while waiting for feedback', subtask_id, self._feedback_wait_timeout)
-                self._tmss_client.set_subtask_status(subtask_id, 'cancelling')
-                self._tmss_client.set_subtask_status(subtask_id, 'cancelled')
+                logger.warning('Feedback for subtask id=%s is overdue and was expected no later than %s! Cancel it or fix the feedback so that this subtask can proceed.', subtask_id, self._feedback_wait_timeout)
 
     def _read_feedback_message_and_process(self, timeout: float=1):
         try:
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index 4968011b312..5e8f8d45fa7 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -184,7 +184,7 @@ def populate_subtask_allowed_state_transitions(apps, schema_editor):
         SubtaskAllowedStateTransitions(old_state=SCHEDULED, new_state=CANCELLING),
         SubtaskAllowedStateTransitions(old_state=QUEUED, new_state=CANCELLING),
         SubtaskAllowedStateTransitions(old_state=STARTED, new_state=CANCELLING),
-        SubtaskAllowedStateTransitions(old_state=FINISHING, new_state=CANCELLING) # when feedback is not complete after a (1 hour) timeout, then the subtask is cancelled.
+        SubtaskAllowedStateTransitions(old_state=FINISHING, new_state=CANCELLING)  # in case feedback is not arriving, a user might choose to cancel a subtask even in this stage
         ])
 
 def populate_settings(apps, schema_editor):
-- 
GitLab