I'm trying to run RQscheduler on a Flask app hosted on Heroku with RedisToGo.
I have set up a worker.py file as follows
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()
My app queues the work with
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)
I have this working locally perfectly fine, but on Heroku I get the following error
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
I'm guessing the issue is because of my Procfile. I don't know if rqscheduler
is actually being run properly, or if RedisToGo is running the redis-server and RQscheduler isn't connected properly to it.
scheduler: rqscheduler
worker: python worker.py
web: python app.py
So rqscheduler was working with localhost when redistogo isn't actually on localhost.
So I updated app.py with
and the Procfile with
Now it's working. All I need to do is figure out how to add env variables into a Procfile.