platform-core/modules/workflowAutomation/engine/scheduleCron.py
ValueOn AG 4a60086c80
Some checks failed
Deploy Plattform-Core (Int) / test (push) Failing after 15s
Deploy Plattform-Core (Int) / deploy (push) Has been skipped
cp adapted to 2026 poweron
2026-06-09 09:53:31 +02:00

35 lines
1.2 KiB
Python

# Copyright (c) 2026 PowerOn AG
# All rights reserved.
"""
Parse cron strings (5-field or 6-field) to APScheduler CronTrigger kwargs.
Frontend produces: "minute hour day month dow" (5-field) or "sec min hour day month dow" (6-field).
"""
import re
from typing import Any, Dict
def parse_cron_to_kwargs(cron: str) -> Dict[str, Any]:
"""
Parse cron string to kwargs for APScheduler CronTrigger.
Supports 5-field (minute hour day month day_of_week) and 6-field (sec min hour day month day_of_week).
Returns dict with: second, minute, hour, day, month, day_of_week.
"""
if not cron or not isinstance(cron, str):
raise ValueError("Invalid cron: empty or not string")
parts = cron.strip().split()
if len(parts) == 5:
minute, hour, day, month, day_of_week = parts
second = "0"
elif len(parts) == 6:
second, minute, hour, day, month, day_of_week = parts
else:
raise ValueError(f"Invalid cron format: expected 5 or 6 fields, got {len(parts)}")
return {
"second": second,
"minute": minute,
"hour": hour,
"day": day,
"month": month,
"day_of_week": day_of_week,
}