我想在Heroku上生产芹菜。到目前为止,我正在开发中,现在我想在生产中部署芹菜。它是一个Django应用程序。它在当地工作正常。
我目前的设置是:
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
但是当我部署它并尝试测试芹菜任务时,服务器(Heroku)记录说
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..
显然,与BROKER_URL
关联的localhost:6379
将无法连接。
在生产中部署时应指向哪个URL?
已更新
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',
)
_ 初始化 _。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'
答案 0 :(得分:0)
BROKER_URL =' redis://127.0.0.1:6379/0'不能在heroku服务器上工作。您需要在heroku中安装两个加载项中的任何一个用于redis
两个附加组件都提供免费套餐计划。
之后你可以指定你的brocker url
BROKER_URL = os.getenv(' REDISTOGO_URL',' redis:// localhost:6379')
因此它可以在local和heroku服务器上运行。
您可以在
中找到详细的文档还有一件事。我个人更喜欢 redistogo 用于heroku。因为redistogo具有比rediscloud更多的功能。
注意:heroku中有更多redis加载项。但他们没有提供免费等级计划。 :)