The following is the steps i took to make a minimal heroku/django/celery/redis project in conjunction with the instructions here along with other sources I found on the web. Hopefully someone will find this useful.
There you have it. A minimal heroku/django/celery/redis project! You can download it here.Instructions on how to deploy this to heroku.
** Note: In the working project the "celery worker" command is already included in the Procfile.
- In your terminal, use the "heroku login" command to log in to the Heroku CLI.
- "git clone https://github.com/heroku/python-getting-started.git" to copy a basic django skeleton project to your local.
- rename python-getting-started to whatever.
- cd into this directory.
- run the following command: "pip install -r requirements.txt" Note: Postgres must be properly installed in order for this step to work properly.
- run the following command: "python manage.py collectstatic"
- Install redis on Mac: "brew install redis"
- Start redis server: "redis-server&" (The & at the end is to run it as a background process)
- Test if Redis server is running: "redis-cli ping". If it replies “PONG”, then it’s good to go!
- Install celery: "pip install celery"
- Make a tasks.py file in your application directory with the following code:
from celery import Celery app = Celery('tasks', broker='redis://localhost:6379/0') @app.task def add(x, y): return x + y
- "cd .." back into root directory.
- Run celery: "celery worker -A=location of tasks&"
- run: "python manage.py shell" in your root directory.
- As your tasks celery server has been started, you can now use it
to run your task just by importing tasks.py script, e.g from Python
interpreter interactive mode:
import hello.tasks hello.tasks.add.delay(1, 1)
- Push your local to heroku master.
consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 61]
Connection refused.
Try restarting the redis server with the command: "brew services restart redis"There you have it. A minimal heroku/django/celery/redis project! You can download it here.Instructions on how to deploy this to heroku.
** Note: In the working project the "celery worker" command is already included in the Procfile.
No comments:
Post a Comment