diff --git a/webservice/webservice.py b/webservice/webservice.py index 293504c3cac4623d7091c13a232bba24f8259ef8..b77183891ddf8320d07a0b55579f289315d4c60b 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -15,11 +15,11 @@ import sys import time import urllib.parse from asyncio import get_event_loop, shield -from datetime import datetime +from datetime import datetime, timezone from pathlib import Path from subprocess import PIPE, run from threading import Thread -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Tuple import yaml import zmq @@ -237,7 +237,7 @@ def change_config(config, updated_config, instrument, return yaml.safe_dump(new_conf, default_flow_style=False).encode() -async def run_proc_async(cmd: List[str]) -> (int, bytes): +async def run_proc_async(cmd: List[str]) -> Tuple[int, bytes]: """Run a subprocess to completion using asyncio, capturing stdout Returns the numeric exit code and stdout (bytes) @@ -427,6 +427,10 @@ def update_job_db(config): except KafkaError: logging.warning("Error sending Kafka notification", exc_info=True) + mdc.update_run_api( + rid, # The result from MyMDC does not matter here. + {'cal_last_end_at': datetime.now(tz=timezone.utc).isoformat()} + ) msg = "\n".join(statii) msg_debug = f"Update MDC {rid}, {msg}" logging.debug(msg_debug.replace('\n', ', ')) @@ -928,6 +932,11 @@ class ActionsServer: request_time, ) await update_mdc_status(self.mdc, 'correct', rid, ret) + loop = get_event_loop() + await loop.run_in_executor( + None, self.mdc.update_run_api, + rid, {'cal_last_begin_at': datetime.now(tz=timezone.utc).isoformat()} + ) # END of part to run after sending reply asyncio.ensure_future(_continue()) @@ -1133,7 +1142,7 @@ class ActionsServer: async def launch_jobs( self, run_nrs, rid, detectors, action, instrument, cycle, proposal, request_time - ) -> (str, List[str]): + ) -> Tuple[str, List[str]]: report = [] ret = [] # run xfel_calibrate