feat(schedule):cron支持图形,RoHS检核增加进度显示

This commit is contained in:
hugo committed 2026-06-15 13:42:15 +08:00
1 parent 6d0e78be81
commit f5aac9c893
46 files changed
+1987 -221

No files matched your search

@@ -9,6 +9,17 @@ from sqlalchemy.orm import joinedload
from app import db
from app.models import ScheduleRun, ScheduleTask
from app.response_utils import utc_iso
from app.services.schedule.timezone_util import (
DEFAULT_SCHEDULE_TIMEZONE,
compute_next_run_at,
normalize_schedule_timezone,
)
def _schedule_timezone_label(task: ScheduleTask | None = None) -> str:
if task is not None:
return normalize_schedule_timezone(getattr(task, "schedule_timezone", None))
return DEFAULT_SCHEDULE_TIMEZONE
def _as_naive_utc(dt: datetime | None) -> datetime | None:
@@ -28,6 +39,7 @@ def serialize_task(task: ScheduleTask, *, last_status: str | None = None) -> dic
'owner_user_id': task.owner_user_id,
'owner_username': task.owner.username if task.owner else None,
'cron_expr': task.cron_expr,
'schedule_timezone': _schedule_timezone_label(task),
'wait_seconds': task.wait_seconds,
'dify_agent_id': task.dify_agent_id,
'platform_api_path': task.platform_api_path,
@@ -82,6 +94,17 @@ def serialize_run(run: ScheduleRun) -> dict:
}
def _repair_next_run_if_needed(task: ScheduleTask) -> bool:
"""启用中但 next_run_at 为空时补算,返回是否发生修改。"""
if not task.enabled or not str(task.cron_expr or '').strip():
return False
if task.next_run_at is not None:
return False
task.schedule_timezone = normalize_schedule_timezone(getattr(task, 'schedule_timezone', None))
task.next_run_at = compute_next_run_at(task.cron_expr, timezone_name=task.schedule_timezone)
return task.next_run_at is not None
def list_tasks() -> list[dict]:
latest_run_subquery = (
db.session.query(
@@ -99,6 +122,13 @@ def list_tasks() -> list[dict]:
.order_by(ScheduleTask.created_at.desc())
.all()
)
repaired = False
for task, _last_status in rows:
if _repair_next_run_if_needed(task):
repaired = True
if repaired:
db.session.commit()
return [serialize_task(task, last_status=last_status) for task, last_status in rows]