Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 423
Olchik Avatar asked Dec 09 '10 11:12

Olchik


2 Answers

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.
    },
}
like image 172
Dhia Avatar answered Oct 03 '22 21:10

Dhia


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

like image 36
asksol Avatar answered Oct 03 '22 22:10

asksol