I have an app that I've launched on Heroku, but the Celery beat process doesn't start when I start the server.
Procfile
web: gunicorn -w 4 connect.wsgi
celery: python manage.py celeryd -c 3 --beat
The worker can be seen to be started after the Heroku app is launched:
$ heroku ps
=== web (Free): gunicorn -w 4 connect.wsgi (1)
web.1: starting 2016/07/13 16:17:18 -0400 (~ 9s ago)
=== celery (Free): python manage.py celeryd -c 3 --beat (1)
celery.1: up 2016/07/13 16:17:25 -0400 (~ 2s ago)
However, in order to get the Celery beat process running, I have to explicitly start it in Heroku with:
heroku run python manage.py celerybeat
Celery beat launches fine locally. Is this a limitation of Heroku or am I doing something wrong?
Celery is fully supported on Heroku and just requires using one of our add-on providers to implement the message broker and result store.
The "shared_task" decorator allows creation of Celery tasks for reusable apps as it doesn't need the instance of the Celery app. It is also easier way to define a task as you don't need to import the Celery app instance.
apply_async(args[, kwargs[, …]]) Sends a task message. delay(*args, **kwargs) Shortcut to send a task message, but doesn't support execution options. calling ( __call__ )
To use the Celery Beat, we need to configure the Redis server in the Django projects settings.py file. As we have installed the Redis server on the local machine, we will point the URL to localhost. The CELERY_TIMEZONE variable must be correctly set to run the tasks at the intended times.
If your running on a free tier heroku with a single dyno then you best bet is to use honcho python clone of foreman a tool for managing Procfile-based applications. clone https://github.com/nickstenning/honcho, This will allow you to fork mutiple processes for your celery beat/workers. You will still be limited by heroku's free tier memory 512MB ram and dyno operating hours. So nothing too heavy good for quick dev and poc's
install honcho
pip install honcho
Ensure honcho is part of your requirement.txt
pip freeze > requirements.txt
Create a ProcfileHoncho store all your original Procfile content
ProcfileHoncho
web: gunicorn myDjangoApp.wsgi --log-file -
worker1: celery -A myDjangoApp beat -l info
worker2: celery -A myDjangoApp worker -l info
Procfile
web: honcho start -f ProcfileHoncho
ensure you load up your broker url via config vars and point to your free managed broker. Am sure you can find one free broker with a quick google search
git push heroku master
heroku logs -t
Check out the logs see if they are any errors. At this point you should be good to go.
Heroku only allow two free Dyno instances in one application if I'm not mistaken.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With