[英]raise ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection refused
minimal django/celery/redis is running locally, but when deployed to heroku gives me the following error, when I run on python:最小的 django/celery/redis 在本地运行,但是当我在 python 上运行时,部署到 heroku 时出现以下错误:
raise ConnectionError(self._error_message(e))
kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection
refused.
This is my tasks.py file in my application directory:这是我的应用程序目录中的 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
Requirements.txt:要求.txt:
django
gunicorn
django-heroku
celery
redis
celery-with-redis
django-celery
kombu
I have set worker dyno to 1. Funny things is i could have sworn it was working before, now it doesnt work for some reason.我已将工人测功机设置为 1。有趣的是,我可以发誓它以前可以工作,但现在由于某种原因它不起作用。
Once, you have a minimal django-celery-redis project setup on local, here is how you deploy it on heroku:曾经,您在本地设置了一个最小的 django-celery-redis项目,下面是在 heroku 上部署它的方法:
Add to your tasks.py:添加到你的tasks.py:
import os app.conf.update(BROKER_URL=os.environ['REDIS_URL'], CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
Make sure your requirements.txt is like this:确保您的 requirements.txt 是这样的:
django gunicorn django-heroku celery redis
Add to your Procfile: "worker: celery worker --app=hello.tasks.app"添加到您的 Procfile:“工人:celery 工人 --app=hello.tasks.app”
Make sure it still runs on local确保它仍然在本地运行
enter into terminal: "export REDIS_URL=redis://"进入终端:“export REDIS_URL=redis://”
run "heroku local&"运行“heroku local&”
run python运行 python
import hello.tasks hello.tasks.add.delay(1,2)
Should return something like:应该返回类似:
<AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
"heroku apps:create minimal-django-celery-redis" “heroku 应用程序:创建最小 django-celery-redis”
"heroku addons:create heroku-redis -a minimal-django-celery-redis" “heroku 插件:创建 heroku-redis -a minimum-django-celery-redis”
"git add." “混帐添加。”
"git commit -m "Demo"" "git commit -m "演示""
"git push heroku master" “git push heroku 主”
"heroku open&" “heroku 打开&”
"heroku ps:scale worker=1" “heroku ps:规模工人=1”
"heroku run python" “heroku 运行 python”
import hello.tasks hello.tasks.add.delay(1, 2)
You should see the task running in the application logs: "heroku logs -t -p worker"您应该会在应用程序日志中看到正在运行的任务:“heroku logs -t -p worker”
This solved it for me, i forgot to import celery in project/ init .py like so这为我解决了,我忘记在 project/ init .py 中导入 celery 像这样
from .celery import app as celery_app
__all__ = ("celery_app",)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.