Skip to content
Snippets Groups Projects
Commit 8e8d740a authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Add some docstrings, type hints

parent bad1af5e
No related branches found
No related tags found
1 merge request!683[Webservice] Restructure database to give more meaningful success/failure information
...@@ -111,9 +111,6 @@ class JobsMonitor: ...@@ -111,9 +111,6 @@ class JobsMonitor:
def do_updates(self): def do_updates(self):
ongoing_jobs_by_exn = self.get_updates_by_exec_id() ongoing_jobs_by_exn = self.get_updates_by_exec_id()
# ^ dict grouping statuses of unfinished jobs by execution ID:
# {12345: ['R-5:41', 'PD-0:00', ...]}
# Newly completed executions are present with an empty list.
# For executions still running, regroup the jobs by request # For executions still running, regroup the jobs by request
# (by run, for correction requests): # (by run, for correction requests):
...@@ -144,7 +141,13 @@ class JobsMonitor: ...@@ -144,7 +141,13 @@ class JobsMonitor:
for req_id in reqs_finished: for req_id in reqs_finished:
self.process_request_finished(req_id) self.process_request_finished(req_id)
def get_updates_by_exec_id(self): def get_updates_by_exec_id(self) -> dict:
"""Get statuses of unfinished jobs, grouped by execution ID
E.g. {12345: ['R-5:41', 'PD-0:00', ...]}
Newly completed executions are present with an empty list.
"""
c = self.job_db.cursor() c = self.job_db.cursor()
c.execute("SELECT job_id, exec_id FROM slurm_jobs WHERE finished = 0") c.execute("SELECT job_id, exec_id FROM slurm_jobs WHERE finished = 0")
...@@ -202,7 +205,7 @@ class JobsMonitor: ...@@ -202,7 +205,7 @@ class JobsMonitor:
self.mymdc_update_dark(mymdc_id, msg) self.mymdc_update_dark(mymdc_id, msg)
def process_execution_finished(self, exec_id): def process_execution_finished(self, exec_id):
"""Send notification that one execution has finished""" """Send notification & record that one execution has finished"""
statuses = [r[0] for r in self.job_db.execute( statuses = [r[0] for r in self.job_db.execute(
"SELECT status FROM slurm_jobs WHERE exec_id = ?", (exec_id,) "SELECT status FROM slurm_jobs WHERE exec_id = ?", (exec_id,)
).fetchall()] ).fetchall()]
...@@ -283,6 +286,7 @@ class JobsMonitor: ...@@ -283,6 +286,7 @@ class JobsMonitor:
self.mymdc_update_dark(r['mymdc_id'], msg, status) self.mymdc_update_dark(r['mymdc_id'], msg, status)
def mymdc_update_run(self, run_id, msg, status='R'): def mymdc_update_run(self, run_id, msg, status='R'):
"""Update correction status in MyMdC"""
data = {'flg_cal_data_status': status, data = {'flg_cal_data_status': status,
'cal_pipeline_reply': msg} 'cal_pipeline_reply': msg}
if status != 'R': if status != 'R':
...@@ -293,6 +297,7 @@ class JobsMonitor: ...@@ -293,6 +297,7 @@ class JobsMonitor:
log.error(Errors.MDC_RESPONSE.format(response)) log.error(Errors.MDC_RESPONSE.format(response))
def mymdc_update_dark(self, dark_run_id, msg, status='IP'): def mymdc_update_dark(self, dark_run_id, msg, status='IP'):
"""Update dark run status in MyMdC"""
data = {'dark_run': {'flg_status': status, data = {'dark_run': {'flg_status': status,
'calcat_feedback': msg}} 'calcat_feedback': msg}}
response = self.mdc.update_dark_run_api(dark_run_id, data) response = self.mdc.update_dark_run_api(dark_run_id, data)
......
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