【问题标题】:My worker Celery works in localhost but not in heroku我的工人 Celery 在本地主机工作,但不在 heroku
【发布时间】:2019-12-27 02:42:30
【问题描述】:

我在我的本地主机(windows)上设置了工作程序,它运行良好,但在 heroku 上它不起作用。

我正在使用 Django、Reddis 和 Celery。

芹菜.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eco_gestao.settings')

app = Celery('eco_gestao')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

过程文件:

web: gunicorn eco_gestao.wsgi --log-file -
worker: celery -A eco_gestao worker -l info

设置:

CELERY_RESULT_BACKEND = 'django-db'
CELERY_BROKER_URL = 'redis://'
# BROKER_URL = os.getenv('REDISTOGO_URL', 'redis://127.0.0.1:6380')
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'

redis_host = os.environ.get('REDIS_HOST', 'localhost')
# Channel layer definitions
# http://channels.readthedocs.org/en/latest/deploying.html#setting-up-a-channel-backend
CHANNEL_LAYERS = {
    "default": {
        # This example app uses the Redis channel layer implementation asgi_redis
        "BACKEND": "asgi_redis.RedisChannelLayer",
        "CONFIG": {
            "hosts": [(redis_host, 6379)],
        },
        "ROUTING": "multichat.routing.channel_routing",
    },
}

错误:

[2019-08-21 17:33:22,075: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error 111 connecting to 127.0.0.1:6379. Connection refused.

【问题讨论】:

  • 你在 Heroku 的本地主机上运行 Redis 吗?如果没有,那就是你的问题......
  • @DejanLekic,我的 Heroku 中有 Heroku Redis 和 Redis Cloud:|

标签: django heroku celery


【解决方案1】:

您必须通过导出正确的 REDIS_HOST 值来配置在 Heroku 上运行的 Celery 以使用您的 Heroku redis(我看到您正在从环境中选择 Redis 主机)。显然这个值没有被导出(这就是你得到Cannot connect to redis://localhost:6379//的原因)。

【讨论】:

  • 哇哦,非常感谢大家的支持。
猜你喜欢
  • 2020-02-02
  • 2020-06-10
  • 1970-01-01
  • 2021-12-01
  • 1970-01-01
  • 2018-10-27
  • 2017-06-05
  • 2023-03-10
  • 2019-07-10
相关资源
最近更新 更多