Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery beat not starting on Heroku

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?

like image 818
Jared Goguen Avatar asked Jul 13 '16 20:07

Jared Goguen


People also ask

Does Celery work on Heroku?

Celery is fully supported on Heroku and just requires using one of our add-on providers to implement the message broker and result store.

What is Shared_task in Celery?

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.

What is Apply_async in Celery?

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__ )

How does Django Celery beat work?

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.


2 Answers

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.

like image 162
Timothy Mugayi Avatar answered Oct 09 '22 18:10

Timothy Mugayi


Heroku only allow two free Dyno instances in one application if I'm not mistaken.

like image 25
Muhlen Avatar answered Oct 09 '22 17:10

Muhlen