aboutsummaryrefslogtreecommitdiff
path: root/qc_app/jobs.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-04-28 09:50:58 +0300
committerFrederick Muriuki Muriithi2022-04-28 09:50:58 +0300
commitdefc1cf0c1635f3262200a9ba25d8bd0c6fc0a93 (patch)
tree8f637c1890037d046b4d63ecb2b9ff582aa506bb /qc_app/jobs.py
parentaadd9aa5dd4c552b573828ddac581a8b7064b0e2 (diff)
downloadgn-uploader-defc1cf0c1635f3262200a9ba25d8bd0c6fc0a93.tar.gz
Update queuing and display results of file parsing
* Make the 'worker' functions free from needing the application context by passing all the details they need as arguments. * Enable the display of parsing results.
Diffstat (limited to 'qc_app/jobs.py')
-rw-r--r--qc_app/jobs.py19
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