Using celery beat with Django
Periodic tasks are one of the most common use cases for Celery. For example, say you want to send periodic emails to your users every week, or create certain summary reports every week. For such repetitive tasks, Celery provides celery beat, which is a scheduler that keeps checking for any scheduled task to be executed at the given time and then runs it. The celery beat worker would create tasks in place of the Django application and put them in the Redis task queue, from where tasks are then picked up by the Celery workers and executed.
Let us learn how to integrate celery beat into our Django project:
- There are multiple ways to create periodic tasks, such as adding a
crontab
configuration in the settings file, or plugging a beat schedule into theapp.conf.beat_schedule
object. They work perfectly, but lack ease of use. One option that truly stands out is using theon_after_finalize.connect
signal.In the following example, we create a periodic...