I want to deploy celery in production on Heroku. Until now I was working under development, now I want to deploy the celery in production. Its a Django app. It works fine locally.
My current settings are :
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
But when I deploy it, and try to test a celery task, the server (Heroku) logs says
Connection error: Error 111 connecting localhost:6379. Connection refused.. Trying again in 20.0 seconds...
2014-03-18T15:24:03.823030+00:00 app[web.1]: 15:24:03 celery.1 | [2014-03-18 15:24:03,822: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379/0: Error 111 connecting localhost:6379. Connection refused..
Obviously, BROKER_URL
being linked to localhost:6379
would not be connected.
Which URL should I point to when deploying in production??
UPDATED
celery.py
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'LlumprsWebsite.settings')
app = Celery('LlumprsWebsite')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)
_ init _.py
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
settings.py
BROKER_URL = 'redis://127.0.0.1:6379/0'
#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
BROKER_URL = 'redis://127.0.0.1:6379/0' won't work on the heroku server. You need to install any of the two add-on in heroku for redis
both add-ons provide free tier plan.
after that you can specify your brocker url
BROKER_URL = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
so it will work on both local and heroku server.
You can find detailed documentation in
One more thing. I personally prefer redistogo for the heroku. Because redistogo has got more features than rediscloud.
Note: There are more redis add-ons available in heroku. but they don't provide free tier plan. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.