How do I schedule a task with celery that runs on 1st of every month?
Asked
Active
Viewed 9,708 times
16
-
Have you read http://celeryq.org/docs/reference/celery.schedules.html ? – Deniz Dogan Dec 09 '10 at 11:11
-
1@Deniz: Doesn't look like that covers DoM. – Ignacio Vazquez-Abrams Dec 09 '10 at 11:19
2 Answers
17
Since Celery 3.0 the crontab schedule now supports day_of_month
and month_of_year
arguments: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules

asksol
- 19,129
- 5
- 61
- 68
10
You can do this using Crontab schedules and you cand define this either:
- in your django settings.py:
from celery.schedules import crontab
CELERYBEAT_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 Celery
from celery.schedules import crontab
app = 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.
},
}

Dhia
- 10,119
- 11
- 58
- 69
-
I can't seem to find documentation on exactly how the '0's are used (I guess they are positional, minute/hour and are not optional, but not seen this explicitly stated) – Dave Engineer Aug 15 '19 at 10:46
-
It's just an interface to linux contrab have a look here to better understand the parameters and how it works: https://linuxconfig.org/linux-crontab-reference-guide – Dhia Aug 15 '19 at 12:44
-
when i added `crontab(0,0,day_of_month='1')` it seems to get executed every second. – suhailvs Mar 04 '21 at 08:49