How to customize celery periodic task time interval?

502 views Asked by At

I need to run schedule every 30 minutes. And I have given cron as */30 * * * and it has scheduling every 30 minutes as

00:30
01:00
01:30
02:00
02:30
.
.
.
00:00

But I want to customize the cron to schedule like

00:45        00:05       00:10
01:15        00:35       00:40
01:45        01:05       01:10
02:15  (or)  01:35  (or) 01:40
02:45        02:05       02:10
.            .            .
.            .            .
.            .            .
00:15        23:35       23:40

How can I give the cron tab to make schedule like this?

I am using django and celery for this and using database scheduler.

PS: I want this to achieve only through cron but not by giving any time delay in the script. Is it possible?

2

There are 2 answers

0
Prabhakar On BEST ANSWER

I believe you can not give cron tabs as per expectation. Instead you shall give individual cron tabs like below..

Day 0 = Sunday
Day 1 = Monday
Day 2 = Tuesday
Day 3 = Wednesday
Day 4 = Thursday
Day 5 = Friday
Day 6 = Saturday

To run tasks on every Sunday, Monday, Thursday, give cron tab like

0 1 0,1,4 * *
5 1 0,1,4 * *
10 1 0,1,4 * *
15 1 0,1,4 * *
20 1 0,1,4 * *
25 1 0,1,4 * *
30 1 0,1,4 * *
35 1 0,1,4 * *
...
...

OR

To run tasks on every Tuesday and Friday, give cron tab like

0 1 2,5 * *
5 1 2,5 * *
10 1 2,5 * *
15 1 2,5 * *
20 1 2,5 * *
25 1 2,5 * *
30 1 2,5 * *
35 1 2,5 * *
...
...

You have to give like above format so that you are able to run your tasks as expected.

0
Christian Pekeler On

Use one of these schedules for your crontab:

15,45 * * * * or 5,35 * * * * or 10,40 * * * *