From be9471a6ad3be101d0e86579da94298c65b331d8 Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Mon, 4 Nov 2019 11:23:44 +0100
Subject: [PATCH] write messages corresponding to action

---
 webservice/messages.py         |  2 ++
 webservice/serve_overview.yaml |  2 +-
 webservice/webservice.py       | 31 ++++++++++++++++++++++---------
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/webservice/messages.py b/webservice/messages.py
index cd15c8148..14c5c8eb1 100644
--- a/webservice/messages.py
+++ b/webservice/messages.py
@@ -22,5 +22,7 @@ class MDC:
 class Success:
     UPLOADED_CONFIG = "SUCCESS: Uploaded config for cycle {}, proposal {}"
     START_CORRECTION = "SUCCESS: Started correction: proposal {}, run {}"
+    START_CHAR = "SUCCESS: Started dark characterization: proposal {}, run {}"
     START_CORRECTION_SIM = "SUCCESS: Started simulated correction: proposal {}, run {}"
+    START_CHAR_SIM = "SUCCESS: Started dark characterization: proposal {}, run {}"
     QUEUED = "Queued proposal {}, run {} for offline calibration"
diff --git a/webservice/serve_overview.yaml b/webservice/serve_overview.yaml
index dea953661..d9dd9c367 100644
--- a/webservice/serve_overview.yaml
+++ b/webservice/serve_overview.yaml
@@ -53,4 +53,4 @@ server-config:
 
 web-service:
     job-db: ./webservice_jobs.sqlite
-    cal-config: /home/karnem/myscratch/calibration3/calibration_configurations/default.yaml
+    cal-config: /home/xcal/calibration_config/
diff --git a/webservice/webservice.py b/webservice/webservice.py
index 9c438a46b..3c1457be9 100644
--- a/webservice/webservice.py
+++ b/webservice/webservice.py
@@ -89,9 +89,9 @@ async def upload_config(socket, config, yaml, instrument, cycle, proposal):
     :param instrument: instrument for which the update is for
     :param cycle: the facility cylce the update is for
     :param proposal: the proposal the update is for
-    
+
     The YAML contents will be placed into a file at
-    
+
         {config.local-path}/{cycle}/{proposal}.yaml
 
     If it exists it is overwritten and then the new version is pushed to
@@ -336,7 +336,7 @@ async def copy_untouched_files(file_list, out_folder, run):
 
 async def run_correction(conn, cmd, mode, proposal, run, rid):
     """ Run a correction command
-    
+
     :param cmd: to run, should be a in list for as expected by subprocess.run
     :param mode: "prod" or "sim", in the latter case nothing will be executed
                  but the command will be logged
@@ -351,7 +351,10 @@ async def run_correction(conn, cmd, mode, proposal, run, rid):
         logging.info(" ".join(cmd))
         ret = subprocess.run(cmd, stdout=subprocess.PIPE)
         if ret.returncode == 0:
-            logging.info(Success.START_CORRECTION.format(proposal, run))
+            if "DARK" in cmd:
+                logging.info(Success.START_CHAR.format(proposal, run))
+            else:
+                logging.info(Success.START_CORRECTION.format(proposal, run))
             # enter jobs in job db
             c = conn.cursor()
             rstr = ret.stdout.decode()
@@ -364,22 +367,32 @@ async def run_correction(conn, cmd, mode, proposal, run, rid):
                                            now=datetime.now().isoformat()))
             conn.commit()
             logging.debug(" ".join(cmd))
-            return Success.START_CORRECTION.format(proposal, run)
+            if "DARK" in cmd:
+                return Success.START_CHAR.format(proposal, run)
+            else:
+                return Success.START_CORRECTION.format(proposal, run)
         else:
             logging.error(Errors.JOB_LAUNCH_FAILED.format(cmd, ret.returncode))
             return Errors.JOB_LAUNCH_FAILED.format(cmd, ret.returncode)
 
     else:
-        logging.debug(Success.START_CORRECTION_SIM.format(proposal, run))
+        if "DARK" in cmd:
+            logging.debug(Success.START_CHAR_SIM.format(proposal, run))
+        else:
+            logging.debug(Success.START_CORRECTION_SIM.format(proposal, run))
+
         logging.debug(cmd)
-        return Success.START_CORRECTION_SIM.format(proposal, run)
+        if "DARK" in cmd:
+            return Success.START_CHAR_SIM.format(proposal, run)
+        else:
+            return Success.START_CORRECTION_SIM.format(proposal, run)
 
 
 async def server_runner(config, mode):
     """ The main server loop
-    
+
     The main server loop handles remote requests via a ZMQ interface.
-    
+
     Requests are the form of ZMQ.REQuest and have the format
 
         command, *parms
-- 
GitLab