Once, you have a minimal django-celery-redis project setup on local, here is how you deploy it on heroku:
- Add to your 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:
django gunicorn django-heroku celery redis
- Add to your Procfile: "worker: celery worker --app=hello.tasks.app"
- Make sure it still runs on local
- enter into terminal: "export REDIS_URL=redis://"
- run "heroku local&"
- run python
import hello.tasks hello.tasks.add.delay(1,2)
<AsyncResult: e1debb39-b61c-47bc-bda3-ee037d34a6c4>
- "heroku apps:create minimal-django-celery-redis"
- "heroku addons:create heroku-redis -a minimal-django-celery-redis"
- "git add ."
- "git commit -m "Demo""
- "git push heroku master"
- "heroku open&"
- "heroku ps:scale worker=1"
- "heroku run 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"
No comments:
Post a Comment