From 5c84a9f48cec0f948b30c893bd4ea84075d5b500 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver <thomas@kluyver.me.uk> Date: Wed, 3 Mar 2021 14:59:37 +0000 Subject: [PATCH] Add return types to several functions --- webservice/webservice.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/webservice/webservice.py b/webservice/webservice.py index cf175f068..0c6775478 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -95,7 +95,7 @@ def init_config_repo(config): logging.info("Config repo is initialized") -async def upload_config(config, yaml, instrument, cycle, proposal): +async def upload_config(config, yaml, instrument, cycle, proposal) -> bytes: """ Upload a new configuration YAML :param config: the configuration defined in the `config-repo` section @@ -156,7 +156,7 @@ def merge(source: Dict, destination: Dict) -> Dict: def change_config(config, updated_config, karabo_id, instrument, - cycle, proposal, apply=False): + cycle, proposal, apply=False) -> bytes: """ Change the configuration of a proposal @@ -260,7 +260,7 @@ async def slurm_job_status(jobid): return "NA", "NA", "NA" -def query_rid(conn, rid): +def query_rid(conn, rid) -> bytes: c = conn.cursor() c.execute("SELECT * FROM jobs WHERE rid LIKE ?", rid) combined = {} @@ -420,7 +420,7 @@ async def copy_untouched_files(file_list, out_folder, run): logging.info("Copying {} to {}".format(f, of)) -async def run_action(job_db, cmd, mode, proposal, run, rid): +async def run_action(job_db, cmd, mode, proposal, run, rid) -> str: """ Run action command (CORRECT OR DARK) :param job_db: jobs database @@ -429,7 +429,7 @@ async def run_action(job_db, cmd, mode, proposal, run, rid): but the command will be logged :param proposal: proposal the command was issued for :param run: run the command was issued for - :param: rid: run id in the MDC + :param rid: run id in the MDC Returns a formatted Success or Error message indicating outcome of the execution. @@ -478,7 +478,7 @@ async def run_action(job_db, cmd, mode, proposal, run, rid): return Success.START_CORRECTION_SIM.format(proposal, run) -async def wait_on_transfer(rpath, max_tries=300): +async def wait_on_transfer(rpath, max_tries=300) -> bool: """ Wait on data files to be transferred to Maxwell @@ -515,7 +515,9 @@ async def wait_on_transfer(rpath, max_tries=300): await asyncio.sleep(10) -async def wait_transfers(wait_runs: List[str], in_folder: str, proposal: str): +async def wait_transfers( + wait_runs: List[str], in_folder: str, proposal: str +) -> bool: """Wait for multiple runs to be transferred to Maxwell. :param wait_runs: Run numbers to wait for @@ -1118,10 +1120,10 @@ class ActionsServer: # Helper methods for handlers --------------------------------------------- @staticmethod - def _normalise_proposal_num(p: str): + def _normalise_proposal_num(p: str) -> str: return "{:06d}".format(int(p.strip('p'))) - def load_proposal_config(self, cycle, proposal): + def load_proposal_config(self, cycle, proposal) -> Dict: # Read calibration configuration from yaml conf_file = Path( self.config['config-repo']['local-path'], cycle, f'{proposal}.yaml' @@ -1140,7 +1142,7 @@ class ActionsServer: async def launch_jobs( self, run_nrs, rid, detectors, action, instrument, cycle, proposal, request_time - ): + ) -> (str, str): # run xfel_calibrate for karabo_id, dconfig in detectors.items(): detector = dconfig['detector-type'] -- GitLab