簡體   English   中英

在Heroku上部署Redis Celery代理時無法訪問

[英]Redis Celery broker not reachable when deployed on Heroku

我想在Heroku的生產中部署芹菜。 到目前為止,我一直在開發中,現在我想在生產中部署芹菜。 它是Django應用。 它在本地工作正常。

我當前的設置是:

BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

但是當我部署它並嘗試測試celery任務時,服務器(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?

更新

芹菜

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'

BROKER_URL ='redis://127.0.0.1:6379/0'在heroku服務器上不起作用。 您需要在heroku中安裝兩個附加組件中的任何一個以進行Redis

這兩個插件均提供免費的套餐。

之后,您可以指定您的Brocker網址

BROKER_URL = os.getenv('REDISTOGO_URL','redis:// localhost:6379')

因此它可以在本地和heroku服務器上使用。

您可以在以下位置找到詳細的文檔

還有一件事。 我個人更喜歡redistogo作為heroku。 因為redistogo具有比rediscloud更多的功能。

注意:heroku中有更多可用的redis附加組件。 但他們不提供免費套餐。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM