你正在阅读 Celery 3.1 的文档。开发版本文档见: 此处.
Schedules define the intervals at which periodic tasks should run.
Raised by crontab_parser when the input can’t be parsed.
Schedule for periodic task.
参数: |
|
---|
Returns tuple of two items (is_due, next_time_to_check), where next time to check is in seconds.
e.g.
time to check is in 20 seconds.
(False, 12.3), means the task is not due, but that the scheduler should check again in 12.3 seconds.
The next time to check is used to save energy/cpu cycles, it does not need to be accurate but will influence the precision of your schedule. You must also keep in mind the value of CELERYBEAT_MAX_LOOP_INTERVAL, which decides the maximum number of seconds the scheduler can sleep between re-checking the periodic task intervals. So if you have a task that changes schedule at runtime then your next_run_at check will decide how long it will take before a change to the schedule takes effect. The max loop interval takes precendence over the next check at value returned.
Scheduler max interval variance
The default max loop interval may vary for different schedulers. For the default scheduler the value is 5 minutes, but for e.g. the django-celery database scheduler the value is 5 seconds.
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, a day of the week, a day of the month, and/or a month in the year in any of the following formats:
The Celery app instance.
It is important to realize that any day on which execution should occur must be represented by entries in all three of the day and month attributes. For example, if day_of_week is 0 and day_of_month is every seventh day, only months that begin on Sunday and are also in the month_of_year attribute will have execution events. Or, day_of_week is 1 and day_of_month is ‘1-7,15-21’ means every first and third monday of every month present in month_of_year.
Returns tuple of two items (is_due, next_time_to_run), where next time to run is in seconds.
See celery.schedules.schedule.is_due() for more information.
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')
[0, 15, 30, 45]
>>> hours = crontab_parser(24).parse('*/4')
[0, 4, 8, 12, 16, 20]
>>> day_of_week = crontab_parser(7).parse('*')
[0, 1, 2, 3, 4, 5, 6]
It can also parse day_of_month and month_of_year expressions if initialized with an minimum of 1. Example usage:
>>> days_of_month = crontab_parser(31, 1).parse('*/3')
[1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31]
>>> months_of_year = crontab_parser(12, 1).parse('*/2')
[1, 3, 5, 7, 9, 11]
>>> months_of_year = crontab_parser(12, 1).parse('2-12/2')
[2, 4, 6, 8, 10, 12]
The maximum possible expanded value returned is found by the formula:
max_ + min_ - 1
Raised by crontab_parser when the input can’t be parsed.