[英]Cannot connect to redis://localhost:6379/0: Error 111 connecting to localhost:6379. Connection refused
[英]raise ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection refused
最小的 django/celery/redis 在本地運行,但是當我在 python 上運行時,部署到 heroku 時出現以下錯誤:
raise ConnectionError(self._error_message(e))
kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection
refused.
這是我的應用程序目錄中的 tasks.py 文件:
from celery import Celery
import os
app = Celery('tasks', broker='redis://localhost:6379/0')
app.conf.update(BROKER_URL=os.environ['REDIS_URL'],
CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
@app.task
def add(x, y):
return x + y
要求.txt:
django
gunicorn
django-heroku
celery
redis
celery-with-redis
django-celery
kombu
我已將工人測功機設置為 1。有趣的是,我可以發誓它以前可以工作,但現在由於某種原因它不起作用。
曾經,您在本地設置了一個最小的 django-celery-redis項目,下面是在 heroku 上部署它的方法:
添加到你的tasks.py:
import os app.conf.update(BROKER_URL=os.environ['REDIS_URL'], CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
確保您的 requirements.txt 是這樣的:
django gunicorn django-heroku celery redis
添加到您的 Procfile:“工人:celery 工人 --app=hello.tasks.app”
確保它仍然在本地運行
進入終端:“export REDIS_URL=redis://”
運行“heroku local&”
運行 python
import hello.tasks hello.tasks.add.delay(1,2)
應該返回類似:
<AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
“heroku 應用程序:創建最小 django-celery-redis”
“heroku 插件:創建 heroku-redis -a minimum-django-celery-redis”
“混帳添加。”
"git commit -m "演示""
“git push heroku 主”
“heroku 打開&”
“heroku ps:規模工人=1”
“heroku 運行 python”
import hello.tasks hello.tasks.add.delay(1, 2)
您應該會在應用程序日志中看到正在運行的任務:“heroku logs -t -p worker”
這為我解決了,我忘記在 project/ init .py 中導入 celery 像這樣
from .celery import app as celery_app
__all__ = ("celery_app",)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.