MCPcopy
hub / github.com/celery/celery / _expand_cronspec

Method _expand_cronspec

celery/schedules.py:434–478  ·  view source on GitHub ↗

Expand cron specification. Takes the given cronspec argument in one of the forms: .. code-block:: text int (like 7) str (like '3-5,*/15', '*', or 'monday') set (like {0,15,30,45} list (like [8-17])

(
            cronspec: Cronspec,
            max_: int, min_: int = 0)

Source from the content-addressed store, hash-verified

432
433 @staticmethod
434 def _expand_cronspec(
435 cronspec: Cronspec,
436 max_: int, min_: int = 0) -> set[Any]:
437 """Expand cron specification.
438
439 Takes the given cronspec argument in one of the forms:
440
441 .. code-block:: text
442
443 int (like 7)
444 str (like '3-5,*/15', '*', or 'monday')
445 set (like {0,15,30,45}
446 list (like [8-17])
447
448 And convert it to an (expanded) set representing all time unit
449 values on which the Crontab triggers. Only in case of the base
450 type being :class:`str`, parsing occurs. (It's fast and
451 happens only once for each Crontab instance, so there's no
452 significant performance overhead involved.)
453
454 For the other base types, merely Python type conversions happen.
455
456 The argument ``max_`` is needed to determine the expansion of
457 ``*`` and ranges. The argument ``min_`` is needed to determine
458 the expansion of ``*`` and ranges for 1-based cronspecs, such as
459 day of month or month of year. The default is sufficient for minute,
460 hour, and day of week.
461 """
462 if isinstance(cronspec, int):
463 result = {cronspec}
464 elif isinstance(cronspec, str):
465 result = crontab_parser(max_, min_).parse(cronspec)
466 elif isinstance(cronspec, set):
467 result = cronspec
468 elif isinstance(cronspec, Iterable):
469 result = set(cronspec) # type: ignore
470 else:
471 raise TypeError(CRON_INVALID_TYPE.format(type=type(cronspec)))
472
473 # assure the result does not precede the min or exceed the max
474 for number in result:
475 if number >= max_ + min_ or number < min_:
476 raise ValueError(CRON_PATTERN_INVALID.format(
477 min=min_, max=max_ - 1 + min_, value=number))
478 return result
479
480 def _delta_to_next(self, last_run_at: datetime, next_hour: int,
481 next_minute: int) -> ffwd:

Callers 3

__init__Method · 0.95

Calls 3

crontab_parserClass · 0.85
parseMethod · 0.45
formatMethod · 0.45