【问题标题】:raise ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection refused引发 ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError:连接到 localhost:6379 的错误 111。拒绝连接
【发布时间】:2020-03-13 01:50:25
【问题描述】:

minimal 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

Requirements.txt:

  django
  gunicorn
  django-heroku
  celery
  redis
  celery-with-redis
  django-celery
  kombu

我已将 worker dyno 设置为 1。 有趣的是我可以发誓它以前可以工作,现在由于某种原因它不起作用。

【问题讨论】:

    标签: django heroku redis celery


    【解决方案1】:

    曾经,您在本地设置了一个minimal django-celery-redis 项目,下面是您在heroku 上部署它的方法:

    1. 添加到你的tasks.py:

       import os
      
       app.conf.update(BROKER_URL=os.environ['REDIS_URL'],
          CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
      
    2. 确保你的 requirements.txt 是这样的:

       django
       gunicorn
       django-heroku
       celery
       redis
      
    3. 添加到您的 Procfile:“worker: celery worker --app=hello.tasks.app”

    4. 确保它仍然在本地运行

    5. 进入终端:“export REDIS_URL=redis://”

    6. 运行“heroku local&”

    7. 运行python

       import hello.tasks
       hello.tasks.add.delay(1,2)
      

    应该返回类似:

        <AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
    
    1. “heroku 应用程序:创建最小 django-celery-redis”

    2. “heroku 插件:创建 heroku-redis -a minimum-django-celery-redis”

    3. “git add .”

    4. "git commit -m "Demo""

    5. “git push heroku 大师”

    6. “heroku 开放&”

    7. "heroku ps:scale worker=1"

    8. “heroku 运行 python”

        import hello.tasks
        hello.tasks.add.delay(1, 2)
      
    9. 您应该会在应用程序日志中看到正在运行的任务:“heroku logs -t -p worker”

    【讨论】:

      猜你喜欢
      • 2020-03-13
      • 2016-07-05
      • 2019-06-16
      • 2017-11-13
      • 2021-06-01
      • 2019-11-28
      • 2022-01-15
      • 2019-10-16
      • 1970-01-01
      相关资源
      最近更新 更多