|
3 | 3 |
|
4 | 4 | from __future__ import absolute_import, print_function, division
|
5 | 5 |
|
| 6 | +from collections import namedtuple |
6 | 7 | import traceback as _traceback
|
7 | 8 | import copy
|
8 | 9 | import math
|
@@ -76,6 +77,19 @@ def is_32bit():
|
76 | 77 |
|
77 | 78 | EPOCH = datetime.datetime.fromtimestamp(0)
|
78 | 79 |
|
| 80 | +ExpressionAlias = namedtuple("ExpressionAlias", "regular, hashed") |
| 81 | + |
| 82 | +# Non-standard expression aliases |
| 83 | +EXPR_ALIASES = { |
| 84 | + "@midnight": ExpressionAlias("0 0 * * *", "h h(0-2) * * * h"), |
| 85 | + "@hourly": ExpressionAlias("0 * * * *", "h * * * * h"), |
| 86 | + "@daily": ExpressionAlias("0 0 * * *", "h h * * * h"), |
| 87 | + "@weekly": ExpressionAlias("0 0 * * 0", "h h * * h h"), |
| 88 | + "@monthly": ExpressionAlias("0 0 1 * *", "h h h * * h"), |
| 89 | + "@yearly": ExpressionAlias("0 0 1 1 *", "h h h h * h"), |
| 90 | + "@annually": ExpressionAlias("0 0 1 1 *", "h h h h * h"), |
| 91 | +} |
| 92 | + |
79 | 93 | # fmt: off
|
80 | 94 | M_ALPHAS = {
|
81 | 95 | "jan": 1, "feb": 2, "mar": 3, "apr": 4, # noqa: E241
|
@@ -823,22 +837,14 @@ def _expand(
|
823 | 837 | # Split the expression in components, and normalize L -> l, MON -> mon,
|
824 | 838 | # etc. Keep expr_format untouched so we can use it in the exception
|
825 | 839 | # messages.
|
826 |
| - expr_aliases = { |
827 |
| - "@midnight": ("0 0 * * *", "h h(0-2) * * * h"), |
828 |
| - "@hourly": ("0 * * * *", "h * * * * h"), |
829 |
| - "@daily": ("0 0 * * *", "h h * * * h"), |
830 |
| - "@weekly": ("0 0 * * 0", "h h * * h h"), |
831 |
| - "@monthly": ("0 0 1 * *", "h h h * * h"), |
832 |
| - "@yearly": ("0 0 1 1 *", "h h h h * h"), |
833 |
| - "@annually": ("0 0 1 1 *", "h h h h * h"), |
834 |
| - } |
835 |
| - |
836 | 840 | efl = expr_format.lower()
|
837 |
| - hash_id_expr = hash_id is not None and 1 or 0 |
838 |
| - try: |
839 |
| - efl = expr_aliases[efl][hash_id_expr] |
840 |
| - except KeyError: |
841 |
| - pass |
| 841 | + |
| 842 | + # Expand expression aliases like `@midnight` |
| 843 | + if efl in EXPR_ALIASES: |
| 844 | + if hash_id is None: |
| 845 | + efl = EXPR_ALIASES[efl].regular |
| 846 | + else: |
| 847 | + efl = EXPR_ALIASES[efl].hashed |
842 | 848 |
|
843 | 849 | expressions = efl.split()
|
844 | 850 |
|
|
0 commit comments