How do I schedule a task with Celery that runs on 1st of every month? How do I schedule a task with Celery that runs on 1st of every month? django django

How do I schedule a task with Celery that runs on 1st of every month?


You can do this using Crontab schedules and you cand define this either:

  • in your django settings.py:
from celery.schedules import crontabCELERYBEAT_SCHEDULE = {    'my_periodic_task': {        'task': 'my_app.tasks.my_periodic_task',        'schedule': crontab(0, 0, day_of_month='1'), # Execute on the first day of every month.    },}
  • in celery.py config:
from celery import Celeryfrom celery.schedules import crontabapp = Celery('app_name')app.conf.beat_schedule = {    'my_periodic_task': {        'task': 'my_app.tasks.my_periodic_task',        'schedule': crontab(0, 0, day_of_month='1'), # Execute on the first day of every month.    },}