From f3dbd994b07401150dfd5974347c8c0818c962bf Mon Sep 17 00:00:00 2001
From: Philipp Schmidt <philipp.schmidt@xfel.eu>
Date: Mon, 3 Mar 2025 09:48:34 +0100
Subject: [PATCH] Move nothing-to-do reply from coroutine to immediate response

---
 webservice/messages.py   |  1 +
 webservice/webservice.py | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/webservice/messages.py b/webservice/messages.py
index 2c586a3a8..e9bbc571d 100644
--- a/webservice/messages.py
+++ b/webservice/messages.py
@@ -5,6 +5,7 @@ class Errors:
     UNKNOWN_ACTION = "FAILED: action {} is not known!, please contact det-support@xfel.eu"
     PATH_NOT_FOUND = "FAILED: run at {} not found!, please contact det-support@xfel.eu"
     NOTHING_TO_DO = "WARN: nothing to calibrate in path {}, please contact det-support@xfel.eu"
+    NOTHING_TO_REDO = "WARN: nothing to re-calibrate in path {}, please contact det-support@xfel.eu"
     CONFIG_ERROR = "FAILED: configuration at {} couldn't be parsed, using default!, please contact det-support@xfel.eu"
     CONFIG_NOT_FOUND = "WARN: configuration at {} not found, using default!, please contact det-support@xfel.eu"
     NO_DEFAULT_CONFIG = "FAILED: No default config for instrument {}, detector {} exists!, please contact det-support@xfel.eu"
diff --git a/webservice/webservice.py b/webservice/webservice.py
index eb539d951..8f79a374a 100644
--- a/webservice/webservice.py
+++ b/webservice/webservice.py
@@ -1279,20 +1279,21 @@ class ActionsServer:
             )
             return msg.encode()
 
+        if len(mddirs_by_krb_id) == 0:
+            in_folder = self.config['correct']['in-folder'].format(
+                instrument=instrument, cycle=cycle, proposal=proposal)
+            rpath = os.path.join(in_folder, f"r{int(runnr):04d}/")
+            msg = Errors.NOTHING_TO_REDO.format(rpath)
+            logging.warning(msg)
+            asyncio.ensure_future(
+                update_mdc_status(self.mdc, 'correct', rid, msg))
+            return msg.encode()
+
         queued_msg = Success.REPROD_QUEUED.format(proposal, [runnr])
         logging.debug(queued_msg)
 
         async def _continue():
             """Runs in the background after we reply to the ZMQ request"""
-            if len(mddirs_by_krb_id) == 0:
-                in_folder = self.config['correct']['in-folder'].format(
-                    instrument=instrument, cycle=cycle, proposal=proposal)
-                rpath = os.path.join(in_folder, f"r{int(runnr):04d}/")
-                msg = Errors.NOTHING_TO_DO.format(rpath)
-                logging.warning(msg)
-                await update_mdc_status(self.mdc, 'correct', rid, msg)
-                return
-
             await update_mdc_status(self.mdc, 'correct', rid, queued_msg)
 
             ret = []
-- 
GitLab