aboutsummaryrefslogtreecommitdiff
path: root/qc_app/jobs.py
diff options
context:
space:
mode:
Diffstat (limited to 'qc_app/jobs.py')
-rw-r--r--qc_app/jobs.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/qc_app/jobs.py b/qc_app/jobs.py
index c5bf5e5..a8257a3 100644
--- a/qc_app/jobs.py
+++ b/qc_app/jobs.py
@@ -3,11 +3,19 @@ import os
import sys
import shlex
import subprocess
-from uuid import uuid4
+from typing import Union
+from uuid import UUID, uuid4
from datetime import timedelta
from redis import Redis
+class JobNotFound(Exception):
+ """Raised if we try to retrieve a non-existent job."""
+
+def raise_jobnotfound(jobid: Union[str,UUID]):
+ """Utility to raise a `NoSuchJobError`"""
+ raise JobNotFound(f"Could not retrieve job '{jobid}'.")
+
def error_filename(job_id, error_dir):
"Compute the path of the file where errors will be dumped."
return f"{error_dir}/job_{job_id}.error"
@@ -70,6 +78,7 @@ def launch_job(the_job: dict, redisurl: str, error_dir):
return the_job
-def job(redis_conn, job_id: str):
+def job(redis_conn, job_id: Union[str,UUID]):
"Retrieve the job"
- return redis_conn.hgetall(job_id)
+ thejob = redis_conn.hgetall(str(job_id)) or raise_jobnotfound(job_id)
+ return thejob