raise ConnectionError(self._error_message(e)) kombu.exceptions.OperationalError: Error 111 connecting to localhost:6379. Connection refused

若如初见. 提交于 2019-12-11 16:59:12

问题


minimal django/celery/redis is running locally, but when deployed to heroku gives me the following error, when I run on python:

 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:

   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

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:

  1. Add to your tasks.py:

     import os
    
     app.conf.update(BROKER_URL=os.environ['REDIS_URL'],
        CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])
    
  2. Make sure your requirements.txt is like this:

     django
     gunicorn
     django-heroku
     celery
     redis
    
  3. Add to your Procfile: "worker: celery worker --app=hello.tasks.app"

  4. Make sure it still runs on local

  5. enter into terminal: "export REDIS_URL=redis://"

  6. run "heroku local&"

  7. run python

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

Should return something like:

    <AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
  1. "heroku apps:create minimal-django-celery-redis"

  2. "heroku addons:create heroku-redis -a minimal-django-celery-redis"

  3. "git add ."

  4. "git commit -m "Demo""

  5. "git push heroku master"

  6. "heroku open&"

  7. "heroku ps:scale worker=1"

  8. "heroku run python"

      import hello.tasks
      hello.tasks.add.delay(1, 2)
    
  9. You should see the task running in the application logs: "heroku logs -t -p worker"



来源:https://stackoverflow.com/questions/58901925/raise-connectionerrorself-error-messagee-kombu-exceptions-operationalerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!