Ken
Ken

Reputation: 179

Celery periodic tasks once in 2 weeks

I am having trouble setting a periodic task with Celery to run once in 2 weeks on Sunday nights. Does anyone have any idea how to configure that with day_of_month day_of_week options?

Upvotes: 3

Views: 2302

Answers (1)

georgexsh
georgexsh

Reputation: 16654

to my knowledge, this couldn't be done solely with crontab

first, make your task run on every Sunday night:

crontab(minute=0, hour=0, day_of_week='sunday')

then, in your task function, check if the week number is even, if so, do nothing:

from datetime import datetime

week_number = int(datetime.today().strftime("%U"))    
if week_number % 2 == 0:
    return

Upvotes: 4

Related Questions