芹菜正在连接到amqp://客人**@本地主机而不是Redis。Heroku部署

2024-04-25 21:01:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我读过一些相似的话题,做了所有建议的事情,但问题依然存在。在

我正在将我的应用程序部署到Heroku。在本地,一切正常,但在部署期间,在指定每个设置后,我可以考虑指定芹菜工人发送以下错误:

:22:50.722826+00:00 app[worker.1]: [2018-10-21 18:22:50,722: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 111] Connection refused.

我尝试从CloudAMQP切换到Redis。问题依然存在。在

以下是我的配置文件:

Django的设置.py:

try: 
    CELERY_BROKER_URL = os.environ['REDIS_URL']
except KeyError: 
    CELERY_BROKER_URL = 'amqp://admin:admin@localhost:5672/admin_host'

try:
    CELERY_RESULT_BACKEND = os.environ['REDIS_URL']
except KeyError:
    CELERY_RESULT_BACKEND = 'amqp://admin:admin@localhost:5672/admin_host'


CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

django_heroku.settings(locals())

芹菜.py

^{pr2}$

来自包含芹菜.py以及设置.py:

from __future__ import absolute_import, unicode_literals

# 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

__all__ = ['celery_app']

而且os.environ['REDIS_URL']确实返回了一个url,我检查过了。在

有人帮忙吗?在


Tags: pyimportredisjsonappurlamqpadmin
1条回答
网友
1楼 · 发布于 2024-04-25 21:01:14

几天来我一直在和这件事斗争,刚贴完这篇文章,我就自己回答了。 虽然我活在这里,也许有人会发现这有用。在

在我的例子中,解决这个问题的关键是我将redis URL硬编码到芹菜.py并在创建celery应用程序对象时将其作为参数传递。在

app=Celery('file_upload',broker_pool_limit=1,broker=redis_url, result_backend=redis_url)

相关问题 更多 >