""" backend/app/services/schedule/cron_util.py 排程 Cron 表达式规范化与校验辅助。 """ from __future__ import annotations def normalize_cron_expr(expr: str | None) -> str: """ 修正常见笔误:* 12,17 * * *(小时内每分钟)→ 0 12,17 * * *(整点)。 """ text = str(expr or '').strip() parts = text.split() if len(parts) == 5 and parts[0] == '*' and parts[1] != '*': parts[0] = '0' return ' '.join(parts) return text def is_risky_cron_expr(expr: str | None) -> bool: """分钟为 * 且小时已限定时,会在该小时内每分钟触发。""" text = str(expr or '').strip() parts = text.split() return len(parts) == 5 and parts[0] == '*' and parts[1] != '*'