diff options
Diffstat (limited to 'qc_app/jobs.py')
-rw-r--r-- | qc_app/jobs.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/qc_app/jobs.py b/qc_app/jobs.py index 908c244..f613e61 100644 --- a/qc_app/jobs.py +++ b/qc_app/jobs.py @@ -4,6 +4,7 @@ from redis import Redis from flask import current_app as app def enqueue_job(delayed_fn, *args, **kwargs): + """Add job to queue""" with Redis.from_url(app.config["REDIS_URL"]) as rconn: job = Job.create( delayed_fn, args, **{ @@ -25,6 +26,7 @@ def enqueue_job(delayed_fn, *args, **kwargs): return job def job(job_id): + "Retrieve the job" with Redis.from_url(app.config["REDIS_URL"]) as rconn: queue = Queue("qcapp_queue", connection=rconn) job = queue.fetch_job(job_id) @@ -32,15 +34,14 @@ def job(job_id): return job -def update_meta(stale_job, **kwargs): - with Redis.from_url(app.config["REDIS_URL"]) as rconn: - queue = Queue("qcapp_queue", connection=rconn) - job = queue.fetch_job(stale_job.get_id()) - job.refresh() - meta_dict = {**stale_job.meta, **job.meta, **kwargs} - for key, val in meta_dict.items(): - job.meta[key] = val +def update_meta(rconn, stale_job, **kwargs): + """Update the job's metadata.""" + job = Job.fetch(stale_job.get_id(), connection=rconn) + job.refresh() + meta_dict = {**stale_job.meta, **job.meta, **kwargs} + for key, val in meta_dict.items(): + job.meta[key] = val - job.save_meta() + job.save_meta() return job |