Run a celery task every 90 mins from 1:30am-6am UTC

432 Views Asked by At

Can we make a celery task run at 1:30, 3:00, 4:30, 6 AM using single crontab function?

i.e 'schedule': crontab(minute=30, hour='1, 3, 4, 6') will run it at 1:30, 3:30, 4:30, 6:30AM

but I want it to run every 90 mins from 1:30 to 6AM

1

There are 1 best solutions below

0
On

I would create two separate schedules (not separate function) as

CELERY_BEAT_SCHEDULE = {
    "task_one": {
        "task": "path.to.task.my_task_function",
        "schedule": crontab(minute="30", hour="1, 4")
    },
    "task_two": {
        "task": "path.to.task.my_task_function",
        "schedule": crontab(hour="3, 6")
    },
}

Here, the schedules are pointing towards the same function named my_task_function(...), but with separate schedules configs.

In this setting, the task_one will execute at 1.30 and 4.30 UTC whereas the task_two will get executed at 3.00 and 6.00 UTC