Would greatly appreciate input from anyone with experience configuring redis as a backend for a celery-brokered django project on heroku. My task scheduling worked fine from localhost but I'm finding it really frustrating getting it deployed on heroku:
- At the moment I'm running 3 dynos, 1 web, 1 scheduler and 1 worker
- I added the redistogo addon to my project. Redistogo set to the free nano plan, which gives me 10 connections, 1 DB and a 5MB size instance
I followed the redistogo documentation (https://devcenter.heroku.com/articles/redistogo#install-redis-in-python) for configuring settings.py and, alternatively, also tried implementing a variation of the solution here. Neither working for me. Here's what I have in settings.py:
redis_url = os.environ.get('REDISTOGO_URL', 'http://localhost:6959') CACHES = { 'default': { 'BACKEND': 'redis_cache.RedisCache',, 'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port), 'OPTIONS': { 'DB': 0, # or 1? 'PASSWORD': redis_url.password, #'PARSER_CLASS': 'redis.connection.HiredisParser' }, }, } CELERY_RESULT_BACKEND = redis_url BROKER_URL = 'redis://localhost:6959/0'
Here's my heroku logs when I try to run the app:
2013-07-11T12:16:10.998516+00:00 app[web.1]: apps = settings.INSTALLED_APPS
2013-07-11T12:16:10.998516+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2013-07-11T12:16:10.998263+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
2013-07-11T12:16:10.998263+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 263, in fetch_command
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
2013-07-11T12:16:10.998516+00:00 app[web.1]: self._setup(name)
2013-07-11T12:16:10.998516+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2013-07-11T12:16:10.998516+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
2013-07-11T12:16:10.998712+00:00 app[web.1]: 'LOCATION': '%s:%s' % (redis_url.hostname, redis_url.port),
2013-07-11T12:16:10.998712+00:00 app[web.1]: AttributeError: 'str' object has no attribute 'hostname'
2013-07-11T12:16:12.201202+00:00 heroku[web.1]: Process exited with status 1
2013-07-11T12:16:12.250743+00:00 heroku[web.1]: State changed from starting to crashed
how do I get redis_url treated like a URI and not a str?
my procfile:
web: python manage.py run_gunicorn -b 0.0.0.0:$PORT -w 3 --log-level info
scheduler: python manage.py celeryd -B -E
worker: python manage.py celeryd -E -B --loglevel=INFO
In requirements I have django-redis-cache==0.10.0, redis==2.7.6, django-celery==3.0.17, celery celery==3.0.20 and kombu==2.5.12