How to get Job by id in python RQ?

So, basically, I want to create a long polling application that uses RQ for the hero. I reviewed this Flask question : going through a background work task (rq, redis) , but that doesn't help.

This is basically what I do.

@app.route('/do_something', methods=['POST']) def get_keywords(): data_json = json.loads(request.data) text = urllib.unquote(data_json["sentence"]) job = q.enqueue(keyword_extraction.extract, text) return job.key @app.route('/do_something/<job_id>', methods=['GET']) def get_keywords_results(job_id): job = Job().fetch(job_id) if(not job.is_finished): return "Not yet", 202 else: return str(job.result) 

Nothing was invented, so when a POST request arrives, it will queue the job and return job_id back to the user, and then the user will use the key to continue polling the result. However, I cannot get this to work, since this line Job().fetch(job_id) returns

NoRedisConnectionException: Could not resolve a Redis connection.

Any help would be really appreciated.

+6
source share
2 answers

I already understood this, in case anyone is interested. That should be just that.

 Job.fetch(job_id, connection=conn) 
+11
source

This is due to the regression, which is now fixed, see https://github.com/nvie/rq/issues/479 for details.

You need to install github master from the branch to enable this until it is released in PyPI.

0
source

All Articles