Files
Neo-ZQYY/apps/backend/app/utils/cron_validator.py
Neo 6f8f12314f feat: 累积功能变更 — 聊天集成、租户管理、小程序更新、ETL 增强、迁移脚本
包含多个会话的累积代码变更:
- backend: AI 聊天服务、触发器调度、认证增强、WebSocket、调度器最小间隔
- admin-web: ETL 状态页、任务管理、调度配置、登录优化
- miniprogram: 看板页面、聊天集成、UI 组件、导航更新
- etl: DWS 新任务(finance_area_daily/board_cache)、连接器增强
- tenant-admin: 项目初始化
- db: 19 个迁移脚本(etl_feiqiu 11 + zqyy_app 8)
- packages/shared: 枚举和工具函数更新
- tools: 数据库工具、报表生成、健康检查
- docs: PRD/架构/部署/合约文档更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 00:03:48 +08:00

35 lines
954 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""Cron 表达式校验工具。
支持标准 5 字段 cron 语法(分 时 日 月 周),
每个字段仅允许 `*` 或对应范围内的数值。
"""
import re
CRON_FIELD_PATTERNS = [
r'(\*|[0-5]?\d)', # minute: 0-59
r'(\*|[01]?\d|2[0-3])', # hour: 0-23
r'(\*|[1-9]|[12]\d|3[01])', # day of month: 1-31
r'(\*|[1-9]|1[0-2])', # month: 1-12
r'(\*|[0-6])', # day of week: 0-6
]
def validate_cron_expression(expr: str) -> bool:
"""校验 5 字段 cron 表达式基本格式。
Args:
expr: 待校验的 cron 表达式字符串,如 ``"0 3 * * 1"``。
Returns:
True 表示格式合法False 表示不合法。
"""
parts = expr.strip().split()
if len(parts) != 5:
return False
for part, pattern in zip(parts, CRON_FIELD_PATTERNS):
if not re.fullmatch(pattern, part):
return False
return True