diff --git a/webservice/serve_overview.py b/webservice/serve_overview.py index bd1281e2bfa077fb97149fbeaa258969715929b5..61185cd47a72810cb7dcb7c626d1cdecf30139f4 100644 --- a/webservice/serve_overview.py +++ b/webservice/serve_overview.py @@ -250,7 +250,8 @@ class RequestHandler(BaseHTTPRequestHandler): last_n_lines = check_output(self.tail_log_cmd, shell=True).decode('utf8').split("\n") last_n_lines = [l for l in last_n_lines - if "Response error from MDC" not in l] + if ("Response error from MDC" not in l + and "DEBUG" not in l)] tmpl = Template(self.templates["log-output"]) log_output_r = tmpl.render(logout="<br>".join(last_n_lines[::-1])) diff --git a/webservice/templates/main_doc.html b/webservice/templates/main_doc.html index 1a35e3a930a05a8fe6439b070fc4d5b2bc0c9def..b848a418aaa640aee5d3eca1e10223fbd11da9ce 100644 --- a/webservice/templates/main_doc.html +++ b/webservice/templates/main_doc.html @@ -7,6 +7,7 @@ <body> {{ maxwell_status }} {{ running_jobs }} +{{ last_characterizations }} {{ request_dark }} {{ log_output }} </body> diff --git a/webservice/webservice.py b/webservice/webservice.py index d9676fce9136886feec6dde03b187d86aba34f7b..3f712aacc8d9ee39c5660f786a710ae1ab6dcce9 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -291,6 +291,8 @@ async def update_job_db(config): flg_order = {"R": 2, "A": 1, "NA": 0} for rid, value in combined.items(): + if rid==0: + continue flgs, statii = value flg = max(flgs, key=lambda i: flg_order[i]) msg = "\n".join(statii) @@ -442,6 +444,8 @@ async def server_runner(config, mode): socket.send(Errors.UNKNOWN_ACTION.format(action).encode()) continue + logging.debug('{}, {}'.format(action, payload)) + if action == "query-rid": rid = payload[0] await query_rid(job_db, socket, rid) @@ -468,59 +472,67 @@ async def server_runner(config, mode): f" {e}: {updated_config}") if action in ['dark', 'correct']: - wait_runs = [] - - if action == 'correct': - rid, sase, instrument, cycle, proposal, runnr, priority = payload - runnr = runnr.replace("r", "") - wait_runs = [runnr] - if action == 'dark': - (rid, sase, instrument, cycle, proposal, - det_list) = payload[:6] - msg = "Dark characterization for {} at {} is requested. " \ - "Checking files..." - logging.info(msg.format(det_list, instrument)) - det_list = det_list.split(',') - runs = payload[6:] # can be many - for i, run in enumerate(runs): - erun = eval(run) - if isinstance(erun, (list, tuple)): - typ, runnr = erun - if typ == "reservation": - req_res = runnr - continue - - runnr = runnr.replace("r", "") - run_mapping[typ] = runnr - wait_runs.append(runnr) - else: - run_mapping['no_mapping_{}'.format(i)] = erun - wait_runs.append(erun) - proposal = proposal.replace("p", "") - proposal = "{:06d}".format(int(proposal)) - specific_conf_file = "{}/{}/{}.yaml".format( - config['config-repo']['local-path'], cycle, proposal) - if os.path.exists(specific_conf_file): - with open(specific_conf_file, "r") as f: - pconf = yaml.load(f.read())[action] - else: - print("Using default file, as {} does not exist".format( - specific_conf_file)) - default_file = "{}/default.yaml".format( - config['config-repo']['local-path']) - with open(default_file, "r") as f: - pconf = yaml.load(f.read())[action] - if instrument not in pconf: - socket.send(Errors.NOT_CONFIGURED.encode()) - return - - in_folder = config[action]['in-folder'].format( - instrument=instrument, cycle=cycle, proposal=proposal) + try: + wait_runs = [] + if action == 'correct': + (rid, sase, instrument, cycle, proposal, runnr, + priority) = payload + runnr = runnr.replace("r", "") + wait_runs = [runnr] + if action == 'dark': + (rid, sase, instrument, cycle, proposal, + det_list) = payload[:6] + msg = "Dark characterization for {} at {} " \ + "is requested. Checking files..." + logging.info(msg.format(det_list, instrument)) + det_list = det_list.split(',') + runs = payload[6:] # can be many + for i, run in enumerate(runs): + erun = eval(run) + if isinstance(erun, (list, tuple)): + typ, runnr = erun + if typ == "reservation": + req_res = runnr + continue + + runnr = runnr.replace("r", "") + run_mapping[typ] = runnr + wait_runs.append(runnr) + else: + run_mapping['no_mapping_{}'.format(i)] = erun + wait_runs.append(erun) + proposal = proposal.replace("p", "") + proposal = "{:06d}".format(int(proposal)) + specific_conf_file = "{}/{}/{}.yaml".format( + config['config-repo']['local-path'], cycle, proposal) + if os.path.exists(specific_conf_file): + with open(specific_conf_file, "r") as f: + pconf = yaml.load(f.read())[action] + else: + default_file = "{}/default.yaml".format( + config['config-repo']['local-path']) + with open(default_file, "r") as f: + pconf = yaml.load(f.read())[action] + if instrument not in pconf: + socket.send(Errors.NOT_CONFIGURED.encode()) + logging.info( + 'Instrument {} in unknown'.format(instrument)) + return + + in_folder = config[action]['in-folder'].format( + instrument=instrument, cycle=cycle, proposal=proposal) + + msg = "Queued proposal {}, run {} for offline calibration, priority: {}".format( + proposal, ", ".join(wait_runs), priority) + socket.send(msg.encode()) + logging.debug(msg) - msg = "Queued proposal {}, run {} for offline calibration, priority: {}".format( - proposal, ", ".join(wait_runs), priority) - socket.send(msg.encode()) - logging.debug(msg) + except Exception as e: + e = str(e) + msg = f"Failure to initiate {action}: {e}" + logging.error(msg) + socket.send(msg.encode()) + return all_transfers = [] for runnr in wait_runs: @@ -558,11 +570,12 @@ async def server_runner(config, mode): Errors.TRANSFER_EVAL_FAILED.format(proposal, runnr)) msg = "Timeout waiting for migration. Contact det-support@xfel.eu" - response = mdc.update_run_api(rid, { - 'flg_cal_data_status': 'NA', - 'cal_pipeline_reply': msg}) - if response.status_code != 200: - logging.error(Errors.MDC_RESPONSE.format(response)) + if action == 'correct': + response = mdc.update_run_api(rid, { + 'flg_cal_data_status': 'NA', + 'cal_pipeline_reply': msg}) + if response.status_code != 200: + logging.error(Errors.MDC_RESPONSE.format(response)) print("All transfers", all(all_transfers)) if not all(all_transfers): @@ -606,12 +619,6 @@ async def server_runner(config, mode): .format(rpath, dconfig["inset"]))) if len(detectors) == 0: logging.warn(Errors.NOTHING_TO_DO.format(rpath)) - msg = "Nothing to characterize for these runs" - response = mdc.update_run_api(rid, { - 'flg_cal_data_status': 'NA', - 'cal_pipeline_reply': msg}) - if response.status_code != 200: - logging.error(Errors.MDC_RESPONSE.format(response)) print("Detectors:", detectors) for detector, dconfig in detectors.items(): @@ -643,7 +650,7 @@ async def server_runner(config, mode): else: cmd += ["--{}".format(key)] ret = await run_correction(job_db, cmd, mode, proposal, - wait_runs[0], rid) + wait_runs[0], 0) status.append(ret) if action == 'correct':