aboutsummaryrefslogtreecommitdiff
path: root/qc_app/jobs.py
blob: dbeb9ce9572b38b01d7804b914572099e67bdbf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from rq import Queue
from redis import Redis
from flask import current_app as app

def enqueue_job(delayed_fn, *args, **kwargs):
    with Redis.from_url(app.config["REDIS_URL"]) as rconn:
        queue = Queue("qcapp_queue", connection=rconn)
        job =  queue.enqueue(delayed_fn, *args, **kwargs)

    job.meta["status"] = "enqueued"
    job.save_meta()
    return job

def job(job_id):
    with Redis.from_url(app.config["REDIS_URL"]) as rconn:
        queue = Queue("qcapp_queue", connection=rconn)
        job = queue.fetch_job(job_id)

    return job