【发布时间】:2014-04-24 10:16:53
【问题描述】:
我想在 Heroku 的生产环境中部署 celery。到目前为止,我一直在开发中,现在我想在生产中部署 celery。它是一个 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..
显然,链接到localhost:6379 的BROKER_URL 将无法连接。
在生产中部署时我应该指向哪个 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'
【问题讨论】:
-
你试过
127.0.0.1吗?由于您的部署似乎在 heroku 上,因此 localhost 可能没有用作别名。 -
我几乎没有使用过heroku,但也许你有一个用于生产中部署的实例的特定URL?也许在您项目的 Redis 设置页面中?
-
我已经用项目中包含的 celery 设置更新了我的问题。请看..
-
看起来 Heroku 上的 Redis 有一个特定的 URL 调用
REDIS_URL -
它要求我验证我的帐户。验证账户后,它要求我添加信用卡详细信息。以为它的基本版是免费的,但我没有信用卡。
标签: python django heroku celery