A crontab can be used as the run_every value of a PeriodicTask to add cron-like scheduling.
Like a cron job, you can specify units of time of when you would like the task to execute. It is a reasonably complete implementation of cron’s features, so it should provide a fair degree of scheduling needs.
You can specify a minute, an hour, and/or a day of the week in any of the following formats:
Parser for crontab expressions. Any expression of the form ‘groups’ (see BNF grammar below) is accepted and expanded to a set of numbers. These numbers represent the units of time that the crontab needs to run on:
digit :: '0'..'9'
dow :: 'a'..'z'
number :: digit+ | dow+
steps :: number
range :: number ( '-' number ) ?
numspec :: '*' | range
expr :: numspec ( '/' steps ) ?
groups :: expr ( ',' expr ) *
The parser is a general purpose one, useful for parsing hours, minutes and day_of_week expressions. Example usage:
minutes = crontab_parser(60).parse("*/15") # yields [0,15,30,45]
hours = crontab_parser(24).parse("*/4") # yields [0,4,8,12,16,20]
day_of_week = crontab_parser(7).parse("*") # yields [0,1,2,3,4,5,6]
Returns tuple of two items (is_due, next_time_to_run), where next time to run is in seconds.
See celery.task.base.PeriodicTask.is_due() for more information.
Returns when the periodic task should run next as a timedelta.