【发布时间】: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:|