我正在尝试使用RedisToGo在Heroku上托管的Flask应用程序上运行RQscheduler。
我已经建立了一个worker.py文件如下
import os
import redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()
我的应用程序将工作与
from redis import Redis
from rq_scheduler import Scheduler
@app.route('/products/create', methods=['POST'])
def product_create_sort():
scheduler = Scheduler(connection=Redis())
scheduler.enqueue_in(timedelta(minutes=5), sort_collection, queue_data)
return Response(status=200)
我在本地工作得很好,但是在Heroku上,我得到了以下错误
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
我猜问题出在我的程序文件上我不知道rqscheduler
是否真的正常运行,或者RedisToGo是否正在运行redis服务器,而RQ调度程序没有正确连接到它。
scheduler: rqscheduler
worker: python worker.py
web: python app.py
2条答案
按热度按时间bakd9h0s1#
所以当redistogo实际上不在localhost上时,rqscheduler正在使用localhost。
所以我更新了app.py,
和Procfile,
现在起作用了我所需要做的就是弄清楚如何将env变量添加到Procfile中。
apeeds0o2#
对于Heroku上的Flask,可以传递Redis URL(我使用
Heroku Data for Redis
;如果你使用其他东西,你的env变量可能会有所不同):PS:此外,不要忘记打开调度dyno,这将规定.