How to get Job by id in RQ python?

python, redis

Solution

I found this out already, in case anybody is interested. It has to be this one instead.

Job.fetch(job_id, connection=conn)

Problem

So, basically I want to build a long-polling application which is using RQ on heroku. I have looked at this question Flask: passing around background worker job (rq, redis) but it doesn't help. This is basically what I'm doing. ``` @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 is fancy, so when the POST request comes, it will queue the job and return job_id back to user immidiately, and then user will use the key to keep polling the result. However, I can't seem to get this to work as this line `Job().fetch(job_id)` returns `NoRedisConnectionException: Could not resolve a Redis connection.` Any help would be really appreciated.

Original source