Passing results to depending on job - python rq

In my own setup, I use two jobs, the second dependent on the results of the first. They are running on separate queues, and if the first job gets successful results, it places a job in the queue for the second, passing the necessary data when it creates the job. It works fairly well for me.

Hope this helps.


You can access info about the current job and its dependencies from within the job itself. This negates the need to explicitly pass the id of the first job.

Define your jobs:

from rq import Queue, get_current_job
from redis import StrictRedis

conn = StrictRedis()
q = Queue('high', connection=conn)

def first_job():
    return 'result of the first job'

def second_job():
    current_job = get_current_job(conn)
    first_job_id = current_job.dependencies[0].id
    first_job_result = q.fetch_job(first_job_id).result
    assert first_job_result == 'result of the first job'

Enqueue your jobs:

first = queue.enqueue(first_job)
second = queue.enqueue(second_job, depends_on=first)

Note that the current_job can have multiple dependencies so current_job.dependencies is a list.