【发布时间】:2019-03-25 21:23:28
【问题描述】:
我已经阅读了类似的主题并完成了建议的所有操作,但问题仍然存在。
我正在将我的应用程序部署到 Heroku。本地一切正常,但在指定每个设置后的部署期间,我可以考虑指定 celery worker 发送以下错误:
:22:50.722826+00:00 app[worker.1]: [2018-10-21 18:22:50,722: ERROR/MainProcess] 消费者:无法连接到 amqp://guest:**@127.0。 0.1:5672//: [Errno 111] 连接被拒绝。
我尝试从 CloudAMQP 切换到 Redis。问题仍然存在。
这是我的配置文件:
Django 的 settings.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())
celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from . import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'file_upload.settings')
app = Celery('file_upload', broker_pool_limit=1)
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
__init__.py 来自包含 celery.py 和 settings.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,我检查了它。
有人帮忙吗?
【问题讨论】:
标签: python django heroku celery