Compare commits

...
Author SHA1 Message Date
praisonai-triage-agent[bot]andMervin Praison 0891b29e9e fix: address review feedback - import ordering and docstring migration
- Move ScheduleParser import before logger assignment (PEP 8 E402)
- Migrate comprehensive docstring from base.py to shared.py
- Preserve original examples (*/6h, */30s) and doctests
- Use explicit re-export syntax to avoid noqa suppressions

Co-authored-by: Mervin Praison <[email protected]>
2026-05-04 05:11:01 +00:00
老憨 4a4b7a3208 refactor: deduplicate ScheduleParser — re-export from shared.py
Two identical ScheduleParser classes existed in scheduler/base.py and
scheduler/shared.py. This removes the duplicate from base.py and
replaces it with a re-export from shared.py (the canonical location).

No behaviour change — scheduler/__init__.py still exports
ScheduleParser via base.py, which now just re-exports from shared.py.

Refs #1602 (Gap 3)
2026-05-04 12:58:02 +08:00
2 changed files with 13 additions and 60 deletions

No files matched your search

+1 -57
View File
@@ -10,67 +10,11 @@ This module provides shared functionality for all schedulers:
import logging
from abc import ABC, abstractmethod
from typing import Any
from .shared import ScheduleParser as ScheduleParser # canonical definition lives in shared.py
logger = logging.getLogger(__name__)
class ScheduleParser:
"""Parse schedule expressions into intervals in seconds."""
@staticmethod
def parse(schedule_expr: str) -> int:
"""
Parse schedule expression and return interval in seconds.
Supported formats:
- "daily" -> 86400 seconds
- "hourly" -> 3600 seconds
- "*/30m" -> 1800 seconds (every 30 minutes)
- "*/6h" -> 21600 seconds (every 6 hours)
- "*/30s" -> 30 seconds (every 30 seconds)
- "3600" -> 3600 seconds (plain number)
Args:
schedule_expr: Schedule expression string
Returns:
Interval in seconds
Raises:
ValueError: If schedule format is not supported
Examples:
>>> ScheduleParser.parse("hourly")
3600
>>> ScheduleParser.parse("*/30m")
1800
>>> ScheduleParser.parse("daily")
86400
"""
schedule_expr = schedule_expr.strip().lower()
if schedule_expr == "daily":
return 86400
elif schedule_expr == "hourly":
return 3600
elif schedule_expr.isdigit():
return int(schedule_expr)
elif schedule_expr.startswith("*/"):
interval_part = schedule_expr[2:]
if interval_part.endswith("m"):
minutes = int(interval_part[:-1])
return minutes * 60
elif interval_part.endswith("h"):
hours = int(interval_part[:-1])
return hours * 3600
elif interval_part.endswith("s"):
return int(interval_part[:-1])
else:
return int(interval_part)
else:
raise ValueError(f"Unsupported schedule format: {schedule_expr}")
class ExecutorInterface(ABC):
"""Abstract interface for executors."""
+12 -3
View File
@@ -1,7 +1,7 @@
"""Shared primitives for sync & async schedulers."""
class ScheduleParser:
"""Shared schedule expression parser for both sync and async schedulers."""
"""Parse schedule expressions into intervals in seconds."""
@staticmethod
def parse(schedule_expr: str) -> int:
@@ -12,8 +12,9 @@ class ScheduleParser:
- "daily" -> 86400 seconds
- "hourly" -> 3600 seconds
- "*/30m" -> 1800 seconds (every 30 minutes)
- "*/1h" -> 3600 seconds (every 1 hour)
- "60" -> 60 seconds (plain number)
- "*/6h" -> 21600 seconds (every 6 hours)
- "*/30s" -> 30 seconds (every 30 seconds)
- "3600" -> 3600 seconds (plain number)
Args:
schedule_expr: Schedule expression string
@@ -23,6 +24,14 @@ class ScheduleParser:
Raises:
ValueError: If schedule format is not supported
Examples:
>>> ScheduleParser.parse("hourly")
3600
>>> ScheduleParser.parse("*/30m")
1800
>>> ScheduleParser.parse("daily")
86400
"""
expr = schedule_expr.strip().lower()