From defc1cf0c1635f3262200a9ba25d8bd0c6fc0a93 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 28 Apr 2022 09:50:58 +0300 Subject: 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. --- qc_app/jobs.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'qc_app/jobs.py') 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 -- cgit v1.2.3