所以,基本上我想要构建一个在Heroku上使用RQ的长轮询应用程序。我已经看过这个问题Flask: passing around background worker job (rq, redis)但它没有帮助。如何通过RQ python中的id获取作业?
这基本上是我在做什么。
@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)
没有什么花哨,所以当POST请求到来时,它将队列中的作业并返回作业ID用户immidiately,然后用户将使用键保持投票的结果。不过,我似乎无法得到这个工作,因为这行Job().fetch(job_id)
回报
NoRedisConnectionException: Could not resolve a Redis connection.
任何帮助将非常感激。
你是否安装了redis adon并正确设置了它? – CraigKerstiens 2013-03-03 04:57:28
我在本地主机上测试过它。当工作入队时它工作正常。但是当我尝试获取Job().fetch(job_id)时,它会给出我的错误。 – toy 2013-03-03 09:57:22