Skip to content
Snippets Groups Projects

[Webservice] Restructure database to give more meaningful success/failure information

Merged Thomas Kluyver requested to merge webservice-refactor-db into master
1 file
+ 12
12
Compare changes
  • Side-by-side
  • Inline
+ 12
12
@@ -269,19 +269,19 @@ class RequestHandler(BaseHTTPRequestHandler):
@@ -269,19 +269,19 @@ class RequestHandler(BaseHTTPRequestHandler):
last_correction_r = Template(tmpl).render(info=last_calib, host=host,
last_correction_r = Template(tmpl).render(info=last_calib, host=host,
port=port)
port=port)
conn = sqlite3.connect(config['web-service']['job-db']).cursor()
conn = sqlite3.connect(config['web-service']['job-db'])
conn.execute("SELECT * FROM jobs WHERE status IN ('R', 'PD', 'CG')")
c = conn.execute(
 
"SELECT status, elapsed, det_type, proposal, run, action FROM "
 
"slurm_jobs INNER JOIN executions USING (exec_id) "
 
"INNER JOIN requests USING (req_id) "
 
"WHERE finished = 0"
 
)
running_jobs = {}
running_jobs = {}
for r in conn.fetchall():
for status, elapsed, det, proposal, run, act in c:
rid, jobid, proposal, run, status, time, det, act = r
key = f'{proposal}/r{int(run):04d}/{det}/{act}'
run = int(run)
flg = "Q" if status in {"QUEUE", "PD"} else "R"
key = '{}/r{:04d}/{}/{}'.format(proposal, run, det, act)
rjobs = running_jobs.setdefault(key, [])
flg = "R"
rjobs.append((flg, f'{status}-{elapsed}'))
if status in ["QUEUE", "PD"]:
flg = "Q"
rjobs = running_jobs.get(key, [])
rjobs.append((flg, '{}-{}'.format(status, time)))
running_jobs[key] = rjobs
tmpl = self.templates["running-jobs"]
tmpl = self.templates["running-jobs"]
running_jobs_r = Template(tmpl).render(running_jobs=running_jobs)
running_jobs_r = Template(tmpl).render(running_jobs=running_jobs)
Loading