MCPcopy
hub / github.com/celery/celery / crontab_parser

Class crontab_parser

celery/schedules.py:196–320  ·  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

194
195
196class crontab_parser:
197 """Parser for Crontab expressions.
198
199 Any expression of the form 'groups'
200 (see BNF grammar below) is accepted and expanded to a set of numbers.
201 These numbers represent the units of time that the Crontab needs to
202 run on:
203
204 .. code-block:: bnf
205
206 digit :: '0'..'9'
207 dow :: 'a'..'z'
208 number :: digit+ | dow+
209 steps :: number
210 range :: number ( '-' number ) ?
211 numspec :: '*' | range
212 expr :: numspec ( '/' steps ) ?
213 groups :: expr ( ',' expr ) *
214
215 The parser is a general purpose one, useful for parsing hours, minutes and
216 day of week expressions. Example usage:
217
218 .. code-block:: pycon
219
220 >>> minutes = crontab_parser(60).parse('*/15')
221 [0, 15, 30, 45]
222 >>> hours = crontab_parser(24).parse('*/4')
223 [0, 4, 8, 12, 16, 20]
224 >>> day_of_week = crontab_parser(7).parse('*')
225 [0, 1, 2, 3, 4, 5, 6]
226
227 It can also parse day of month and month of year expressions if initialized
228 with a minimum of 1. Example usage:
229
230 .. code-block:: pycon
231
232 >>> days_of_month = crontab_parser(31, 1).parse('*/3')
233 [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31]
234 >>> months_of_year = crontab_parser(12, 1).parse('*/2')
235 [1, 3, 5, 7, 9, 11]
236 >>> months_of_year = crontab_parser(12, 1).parse('2-12/2')
237 [2, 4, 6, 8, 10, 12]
238
239 The maximum possible expanded value returned is found by the formula:
240
241 :math:`max_ + min_ - 1`
242 """
243
244 ParseException = ParseException
245
246 _range = r'(\w+?)-(\w+)'
247 _steps = r'/(\w+)?'
248 _star = r'\*'
249
250 def __init__(self, max_: int = 60, min_: int = 0):
251 self.max_ = max_
252 self.min_ = min_
253 self.pats: tuple[tuple[re.Pattern, Callable], ...] = (

Calls

no outgoing calls