Search code examples
pythondjangoceleryperiodic-task

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?


Solution

  • 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