问题
I'm attempting to create a python rq worker on heroku for my flask app. The heroku documentation provides the following example code for creating a worker:
https://devcenter.heroku.com/articles/python-rq#create-a-worker
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()
Thing is: I am using RedisCloud and replacing REDISTOGO_URL with REDISCLOUD_URL is not working. It's fine loading locally but when I upload to heroku I am seeing in the logs it is still attempting to connect to localhost.
2015-02-25T00:11:53.445167+00:00 app[web.1]: ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
The RedisCloud documentation only lists working with Python, not particularly flask, so the below code did not change my situation at all:
# -*- coding: utf-8 -*-
import os
import urlparse
import redis
from rq import Worker, Queue, Connection
listen = ['high', 'default', 'low']
redis_url = urlparse.urlparse(os.environ.get('REDISCLOUD_URL', 'redis://localhost:6379'))
conn = redis.from_url(redis_url.hostname)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()
i have confirmed that the REDISCLOUD_URL var is present on heroku via:
$heroku config:get REDISCLOUD_URL
in format:
http://rediscloud:password@hostname:port
I can find no documentation on what the redis.from_url() function does or what parameters it accepts.
What am I missing here to get this worker to look to the server var for heroku and not localhost?
来源:https://stackoverflow.com/questions/28709035/how-to-setup-an-rq-worker-on-heroku-with-rediscloud-using-flask