MCPcopy Create free account
hub / github.com/celery/celery / crontab_parser

Class crontab_parser

celery/schedules.py:227–351  ·  view source on GitHub ↗

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: .. code-block:: bnf digit :: '0'..'9' dow

Source from the content-addressed store, hash-verified

225
226
227class crontab_parser:
228 """Parser for Crontab expressions.
229
230 Any expression of the form 'groups'
231 (see BNF grammar below) is accepted and expanded to a set of numbers.
232 These numbers represent the units of time that the Crontab needs to
233 run on:
234
235 .. code-block:: bnf
236
237 digit :: '0'..'9'
238 dow :: 'a'..'z'
239 number :: digit+ | dow+
240 steps :: number
241 range :: number ( '-' number ) ?
242 numspec :: '*' | range
243 expr :: numspec ( '/' steps ) ?
244 groups :: expr ( ',' expr ) *
245
246 The parser is a general purpose one, useful for parsing hours, minutes and
247 day of week expressions. Example usage:
248
249 .. code-block:: pycon
250
251 >>> minutes = crontab_parser(60).parse('*/15')
252 [0, 15, 30, 45]
253 >>> hours = crontab_parser(24).parse('*/4')
254 [0, 4, 8, 12, 16, 20]
255 >>> day_of_week = crontab_parser(7).parse('*')
256 [0, 1, 2, 3, 4, 5, 6]
257
258 It can also parse day of month and month of year expressions if initialized
259 with a minimum of 1. Example usage:
260
261 .. code-block:: pycon
262
263 >>> days_of_month = crontab_parser(31, 1).parse('*/3')
264 [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31]
265 >>> months_of_year = crontab_parser(12, 1).parse('*/2')
266 [1, 3, 5, 7, 9, 11]
267 >>> months_of_year = crontab_parser(12, 1).parse('2-12/2')
268 [2, 4, 6, 8, 10, 12]
269
270 The maximum possible expanded value returned is found by the formula:
271
272 :math:`max_ + min_ - 1`
273 """
274
275 ParseException = ParseException
276
277 _range = r'(\w+?)-(\w+)'
278 _steps = r'/(\w+)?'
279 _star = r'\*'
280
281 def __init__(self, max_: int = 60, min_: int = 0):
282 self.max_ = max_
283 self.min_ = min_
284 self.pats: tuple[tuple[re.Pattern, Callable], ...] = (

Calls

no outgoing calls