Sunday 17 November 2019

Instructions on how to deploy a minimal heroku/django/celery/redis project on heroku

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"

No comments:

Post a Comment

Featured post

Popular Posts