3

I've looked at similar questions asked/answered here, but I can't figure out my issue. My flask app, when deployed on heroku, isn't connecting to my heroku-redis instance. Instead, in my heroku logs, I am getting:

2018-05-10T20:36:12.520794+00:00 heroku[web.1]: Starting process with command `flask db upgrade; flask translate compile; gunicorn microblog:app`
2018-05-10T20:36:12.705812+00:00 heroku[worker.1]: Starting process with command `rq worker microblog-tasks`
2018-05-10T20:36:13.385204+00:00 heroku[worker.1]: State changed from starting to up
2018-05-10T20:36:15.060614+00:00 heroku[worker.1]: Process exited with status 1
2018-05-10T20:36:15.080485+00:00 heroku[worker.1]: State changed from up to crashed
2018-05-10T20:36:14.989923+00:00 app[worker.1]: Error 111 connecting to localhost:6379. Connection refused.

Why is my worker so determined to connect to my local redis server? My procfile is:

web: flask db upgrade; flask translate compile; gunicorn microblog:app
worker: rq worker microblog-tasks

Running "heroku config:get REDIS_URL" shows that the env var REDIS_URL is indeed set in heroku. Do background tasks require more than one dyno? I have no trouble with my app locally, just when deploying on heroku.

Separate but related question: What are the differences between redis, redistogo, and rediscloud? When would one use each of them? Really appreciate any help.

James Parsons
  • 6,097
  • 12
  • 68
  • 108
Rohan Kadakia
  • 334
  • 2
  • 12
  • Did you add logging in your app to make sure that the `Config.REDIS_URL` item is correctly imported from the `REDIS_URL` environment variable? The logs show that the connection is going to `localhost:6379`, so a likely problem is that redis is connecting to the default service url. – Miguel Grinberg May 11 '18 at 11:59
  • Thanks for your response. I don't see why Config.REDIS_URL isn't being correctly imported from the REDIS_URL environment variable. Since it is working for you, could you show me what I SHOULD be seeing in the heroku logs? – Rohan Kadakia May 11 '18 at 17:31
  • I don't have the application deployed with the Redis queue at this time. You did not answer my question. Did you check what the value of `Config.REDIS_URL` is? – Miguel Grinberg May 12 '18 at 05:07
  • Using a print statement and checking the heroku logs, the value of app.config['REDIS_URL'] is correct. It's the same as I get with "heroku config:get REDIS_URL". It is NOT "redis://localhost:6379". How should I proceed? Thank you. – Rohan Kadakia May 12 '18 at 05:19
  • You added the print statement for the worker process, correct? Because the error is for that process, the log snippet that you pasted in your question does not show errors for the web process. Are you using the microblog application, or is this something that you built? – Miguel Grinberg May 13 '18 at 02:29
  • Actually, I think I know what's going on. Try changing the second line in your `Procfile` to `worker: rq worker -u $REDIS_URL microblog-tasks`. Looks like I missed the URL in the Heroku example, it is in the Docker example that follows. – Miguel Grinberg May 13 '18 at 02:36
  • Now it works. Thanks, Miguel!! If you put this as the answer, I will accept it. – Rohan Kadakia May 13 '18 at 23:45

1 Answers1

1

There was actually an omission in my article, I apologize for that.

The command that starts the RQ worker needs to include the connection URL for Redis:

worker: rq worker -u $REDIS_URL microblog-tasks
Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152