fix: record cancelled cron runs

maintainer edit: treat job-level CancelledError as a failed cron run so bound automation cancellations update run history and do not break subsequent scheduling.
This commit is contained in:
chengyongru
2026-06-11 22:01:23 +08:00
parent a326ba40f4
commit f82ab9f192
2 changed files with 34 additions and 0 deletions
+7
View File
@@ -448,6 +448,13 @@ class CronService:
job.state.last_error = None
logger.info("Cron: job '{}' completed", job.name)
except asyncio.CancelledError as e:
current = asyncio.current_task()
if current is not None and current.cancelling():
raise
job.state.last_status = "error"
job.state.last_error = str(e) or e.__class__.__name__
logger.exception("Cron: job '{}' was cancelled", job.name)
except Exception as e:
job.state.last_status = "error"
job.state.last_error = str(e)