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

Create correction reports in MyMdC when jobs have finished

parent e80a4e2a
No related branches found
No related tags found
1 merge request!943[Webservice] Create correction reports in MyMdC when jobs have finished
...@@ -79,7 +79,7 @@ install_requires = [ ...@@ -79,7 +79,7 @@ install_requires = [
"lxml==4.5.0", "lxml==4.5.0",
"markupsafe==2.0.1", "markupsafe==2.0.1",
"matplotlib==3.4.2", "matplotlib==3.4.2",
"metadata_client==3.0.8", "metadata_client==4.0.0",
"nbclient==0.5.1", "nbclient==0.5.1",
"nbconvert==5.6.1", "nbconvert==5.6.1",
"nbformat==5.0.7", "nbformat==5.0.7",
......
...@@ -3,6 +3,8 @@ import argparse ...@@ -3,6 +3,8 @@ import argparse
import json import json
import locale import locale
import logging import logging
import os.path
import shlex
import signal import signal
import time import time
from datetime import datetime, timezone from datetime import datetime, timezone
...@@ -232,7 +234,7 @@ class JobsMonitor: ...@@ -232,7 +234,7 @@ class JobsMonitor:
).fetchall()] ).fetchall()]
success = set(statuses) == {'COMPLETED'} success = set(statuses) == {'COMPLETED'}
r = self.job_db.execute( r = self.job_db.execute(
"SELECT det_type, karabo_id, req_id, proposal, run, action " "SELECT det_type, karabo_id, command, req_id, proposal, run, action, mymdc_id "
"FROM executions JOIN requests USING (req_id)" "FROM executions JOIN requests USING (req_id)"
"WHERE exec_id = ?", "WHERE exec_id = ?",
(exec_id,) (exec_id,)
...@@ -259,6 +261,10 @@ class JobsMonitor: ...@@ -259,6 +261,10 @@ class JobsMonitor:
log.warning("Error sending Kafka notification", log.warning("Error sending Kafka notification",
exc_info=True) exc_info=True)
self.record_correction_report(
r['mymdc_id'], r['command'], r['karabo_id'], success
)
return r['req_id'] return r['req_id']
def process_request_finished(self, req_id): def process_request_finished(self, req_id):
...@@ -331,9 +337,44 @@ class JobsMonitor: ...@@ -331,9 +337,44 @@ class JobsMonitor:
log.error("Failed to update MDC dark run id %s", dark_run_id) log.error("Failed to update MDC dark run id %s", dark_run_id)
log.error(Errors.MDC_RESPONSE.format(response)) log.error(Errors.MDC_RESPONSE.format(response))
def record_correction_report(self, mymdc_run_id, command, karabo_id, success):
"""Add report to MyMdC when a correction execution has finished"""
args = shlex.split(command)
try:
report_path = args[args.index("--report-to") + 1] + ".pdf"
except (ValueError, IndexError):
log.warning("Couldn't find report path in %r", args)
return
if not os.path.isfile(report_path):
log.warning("Jobs finished, but report file %s missing", report_path)
return
ts = datetime.fromtimestamp(os.stat(report_path).st_mtime, tz=timezone.utc)
desc = f"{karabo_id} detector corrections"
if not success:
desc += " (errors occurred)"
log.debug("Adding report file %s to MDC for run ID %s",
report_path, mymdc_run_id)
response = self.mdc.create_report_api({
"name": os.path.basename(report_path),
"cal_report_path": os.path.dirname(report_path).rstrip('/') + '/',
"cal_report_at": ts.isoformat(),
"run_id": mymdc_run_id,
"description": desc,
})
if response.status_code >= 400:
log.error("Failed to add report to MDC for run ID %s: HTTP status %s",
mymdc_run_id, response.status_code)
def interrupted(signum, frame): def interrupted(signum, frame):
raise KeyboardInterrupt raise KeyboardInterrupt
def main(argv=None): def main(argv=None):
# Ensure files are opened as UTF-8 by default, regardless of environment. # Ensure files are opened as UTF-8 by default, regardless of environment.
locale.setlocale(locale.LC_CTYPE, ('en_US', 'UTF-8')) locale.setlocale(locale.LC_CTYPE, ('en_US', 'UTF-8'))
......
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