fix(cron): preserve schedules edited during execution

This commit is contained in:
fhgffy authored and Xubin Ren committed 2026-10-18 22:11:14 +08:00
1 parent 59bfdc895b
commit a3ead61580
2 files changed
+86 -2

No files matched your search

+8 -2
View File
@@ -6,7 +6,7 @@ import time
import uuid
from contextlib import suppress
from copy import deepcopy
from dataclasses import asdict
from dataclasses import asdict, replace
from datetime import datetime
from pathlib import Path
from types import EllipsisType
@@ -604,6 +604,7 @@ class CronService:
async def _execute_job(self, job: CronJob) -> None:
"""Execute a single job."""
schedule = job.schedule
start_ms = _now_ms()
logger.info("Cron: executing job '{}' ({})", job.name, job.id)
result: str | CronRunResult | None = None
@@ -646,6 +647,10 @@ class CronService:
))
job.state.run_history = job.state.run_history[-self._MAX_RUN_HISTORY:]
# Completion belongs to the schedule that started this run.
if job.schedule is not schedule:
return
# Handle one-shot jobs
if job.schedule.kind == "at":
if job.delete_after_run:
@@ -895,7 +900,8 @@ class CronService:
schedule_changed = schedule is not None and schedule != job.schedule
if schedule is not None:
_validate_schedule_for_add(schedule)
job.schedule = schedule
if schedule_changed:
job.schedule = replace(schedule)
if name is not None:
job.name = name
if message is not None: