Skip to content
Advertisement

Celery jobs not running on heroku (python/django app)

I have a Django app setup with some scheduled tasks. The app is deployed on Heroku with Redis. The task runs if invoked synchronously in the console, or locally when I also have redis and celery running. However, the scheduled jobs are not running on Heroku.

My task:

JavaScript

celery.py:

JavaScript

In Procfile: worker: celery -A my_app worker --beat -S django -l info

I’ve spun up the worker with heroku ps:scale worker=1 -a my-app. I can see the registered tasks under [tasks] in the worker logs. However, the scheduled tasks are not running at their scheduled time. Calling send_emails.delay() in the production console does work. How do I get the worker to stay alive and / or run the job at the scheduled time?

I have a workaround using a command and heroku scheduler. Just unsure if that’s the best way to do it.

Advertisement

Answer

If you’re on free demo, you should know that heroku server sleeps and if your scheduled task becomes due when your server is sleeping, it won’t run.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement