Skip to content
Snippets Groups Projects
Commit 0cbcb9d3 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Merge branch 'fix/catch_exceptions' into 'master'

Fix: Catch exception due to user input

See merge request detectors/pycalibration!186
parents 7daa2edf 64335899
No related branches found
No related tags found
1 merge request!186Fix: Catch exception due to user input
...@@ -250,7 +250,8 @@ class RequestHandler(BaseHTTPRequestHandler): ...@@ -250,7 +250,8 @@ class RequestHandler(BaseHTTPRequestHandler):
last_n_lines = check_output(self.tail_log_cmd, last_n_lines = check_output(self.tail_log_cmd,
shell=True).decode('utf8').split("\n") shell=True).decode('utf8').split("\n")
last_n_lines = [l for l in last_n_lines 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"]) tmpl = Template(self.templates["log-output"])
log_output_r = tmpl.render(logout="<br>".join(last_n_lines[::-1])) log_output_r = tmpl.render(logout="<br>".join(last_n_lines[::-1]))
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<body> <body>
{{ maxwell_status }} {{ maxwell_status }}
{{ running_jobs }} {{ running_jobs }}
{{ last_characterizations }}
{{ request_dark }} {{ request_dark }}
{{ log_output }} {{ log_output }}
</body> </body>
......
...@@ -291,6 +291,8 @@ async def update_job_db(config): ...@@ -291,6 +291,8 @@ async def update_job_db(config):
flg_order = {"R": 2, "A": 1, "NA": 0} flg_order = {"R": 2, "A": 1, "NA": 0}
for rid, value in combined.items(): for rid, value in combined.items():
if rid==0:
continue
flgs, statii = value flgs, statii = value
flg = max(flgs, key=lambda i: flg_order[i]) flg = max(flgs, key=lambda i: flg_order[i])
msg = "\n".join(statii) msg = "\n".join(statii)
...@@ -442,6 +444,8 @@ async def server_runner(config, mode): ...@@ -442,6 +444,8 @@ async def server_runner(config, mode):
socket.send(Errors.UNKNOWN_ACTION.format(action).encode()) socket.send(Errors.UNKNOWN_ACTION.format(action).encode())
continue continue
logging.debug('{}, {}'.format(action, payload))
if action == "query-rid": if action == "query-rid":
rid = payload[0] rid = payload[0]
await query_rid(job_db, socket, rid) await query_rid(job_db, socket, rid)
...@@ -468,59 +472,67 @@ async def server_runner(config, mode): ...@@ -468,59 +472,67 @@ async def server_runner(config, mode):
f" {e}: {updated_config}") f" {e}: {updated_config}")
if action in ['dark', 'correct']: if action in ['dark', 'correct']:
wait_runs = [] try:
wait_runs = []
if action == 'correct': if action == 'correct':
rid, sase, instrument, cycle, proposal, runnr, priority = payload (rid, sase, instrument, cycle, proposal, runnr,
runnr = runnr.replace("r", "") priority) = payload
wait_runs = [runnr] runnr = runnr.replace("r", "")
if action == 'dark': wait_runs = [runnr]
(rid, sase, instrument, cycle, proposal, if action == 'dark':
det_list) = payload[:6] (rid, sase, instrument, cycle, proposal,
msg = "Dark characterization for {} at {} is requested. " \ det_list) = payload[:6]
"Checking files..." msg = "Dark characterization for {} at {} " \
logging.info(msg.format(det_list, instrument)) "is requested. Checking files..."
det_list = det_list.split(',') logging.info(msg.format(det_list, instrument))
runs = payload[6:] # can be many det_list = det_list.split(',')
for i, run in enumerate(runs): runs = payload[6:] # can be many
erun = eval(run) for i, run in enumerate(runs):
if isinstance(erun, (list, tuple)): erun = eval(run)
typ, runnr = erun if isinstance(erun, (list, tuple)):
if typ == "reservation": typ, runnr = erun
req_res = runnr if typ == "reservation":
continue req_res = runnr
continue
runnr = runnr.replace("r", "")
run_mapping[typ] = runnr runnr = runnr.replace("r", "")
wait_runs.append(runnr) run_mapping[typ] = runnr
else: wait_runs.append(runnr)
run_mapping['no_mapping_{}'.format(i)] = erun else:
wait_runs.append(erun) run_mapping['no_mapping_{}'.format(i)] = erun
proposal = proposal.replace("p", "") wait_runs.append(erun)
proposal = "{:06d}".format(int(proposal)) proposal = proposal.replace("p", "")
specific_conf_file = "{}/{}/{}.yaml".format( proposal = "{:06d}".format(int(proposal))
config['config-repo']['local-path'], cycle, proposal) specific_conf_file = "{}/{}/{}.yaml".format(
if os.path.exists(specific_conf_file): config['config-repo']['local-path'], cycle, proposal)
with open(specific_conf_file, "r") as f: if os.path.exists(specific_conf_file):
pconf = yaml.load(f.read())[action] with open(specific_conf_file, "r") as f:
else: pconf = yaml.load(f.read())[action]
print("Using default file, as {} does not exist".format( else:
specific_conf_file)) default_file = "{}/default.yaml".format(
default_file = "{}/default.yaml".format( config['config-repo']['local-path'])
config['config-repo']['local-path']) with open(default_file, "r") as f:
with open(default_file, "r") as f: pconf = yaml.load(f.read())[action]
pconf = yaml.load(f.read())[action] if instrument not in pconf:
if instrument not in pconf: socket.send(Errors.NOT_CONFIGURED.encode())
socket.send(Errors.NOT_CONFIGURED.encode()) logging.info(
return 'Instrument {} in unknown'.format(instrument))
return
in_folder = config[action]['in-folder'].format(
instrument=instrument, cycle=cycle, proposal=proposal) 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( except Exception as e:
proposal, ", ".join(wait_runs), priority) e = str(e)
socket.send(msg.encode()) msg = f"Failure to initiate {action}: {e}"
logging.debug(msg) logging.error(msg)
socket.send(msg.encode())
return
all_transfers = [] all_transfers = []
for runnr in wait_runs: for runnr in wait_runs:
...@@ -558,11 +570,12 @@ async def server_runner(config, mode): ...@@ -558,11 +570,12 @@ async def server_runner(config, mode):
Errors.TRANSFER_EVAL_FAILED.format(proposal, Errors.TRANSFER_EVAL_FAILED.format(proposal,
runnr)) runnr))
msg = "Timeout waiting for migration. Contact det-support@xfel.eu" msg = "Timeout waiting for migration. Contact det-support@xfel.eu"
response = mdc.update_run_api(rid, { if action == 'correct':
'flg_cal_data_status': 'NA', response = mdc.update_run_api(rid, {
'cal_pipeline_reply': msg}) 'flg_cal_data_status': 'NA',
if response.status_code != 200: 'cal_pipeline_reply': msg})
logging.error(Errors.MDC_RESPONSE.format(response)) if response.status_code != 200:
logging.error(Errors.MDC_RESPONSE.format(response))
print("All transfers", all(all_transfers)) print("All transfers", all(all_transfers))
if not all(all_transfers): if not all(all_transfers):
...@@ -606,12 +619,6 @@ async def server_runner(config, mode): ...@@ -606,12 +619,6 @@ async def server_runner(config, mode):
.format(rpath, dconfig["inset"]))) .format(rpath, dconfig["inset"])))
if len(detectors) == 0: if len(detectors) == 0:
logging.warn(Errors.NOTHING_TO_DO.format(rpath)) 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) print("Detectors:", detectors)
for detector, dconfig in detectors.items(): for detector, dconfig in detectors.items():
...@@ -643,7 +650,7 @@ async def server_runner(config, mode): ...@@ -643,7 +650,7 @@ async def server_runner(config, mode):
else: else:
cmd += ["--{}".format(key)] cmd += ["--{}".format(key)]
ret = await run_correction(job_db, cmd, mode, proposal, ret = await run_correction(job_db, cmd, mode, proposal,
wait_runs[0], rid) wait_runs[0], 0)
status.append(ret) status.append(ret)
if action == 'correct': if action == 'correct':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment