fix: display cron last_run_at in local timezone (#7625)

This commit is contained in:
時壹
2026-04-17 19:36:47 +09:00
committed by GitHub
parent a1a7de1c57
commit 47f78be378
2 changed files with 10 additions and 4 deletions

View File

@@ -196,7 +196,9 @@ class CronJobManager:
def _get_next_run_time(self, job_id: str):
aps_job = self.scheduler.get_job(job_id)
return aps_job.next_run_time if aps_job else None
if not aps_job or aps_job.next_run_time is None:
return None
return aps_job.next_run_time.astimezone(timezone.utc)
async def _run_job(self, job_id: str) -> None:
job = await self.db.get_cron_job(job_id)

View File

@@ -1,5 +1,5 @@
import traceback
from datetime import datetime
from datetime import datetime, timezone
from quart import jsonify, request
@@ -26,8 +26,12 @@ class CronRoute(Route):
def _serialize_job(self, job) -> dict:
data = job.model_dump() if hasattr(job, "model_dump") else job.__dict__
for k in ["created_at", "updated_at", "last_run_at", "next_run_time"]:
if isinstance(data.get(k), datetime):
data[k] = data[k].isoformat()
v = data.get(k)
if isinstance(v, datetime):
# Attach UTC
if v.tzinfo is None:
v = v.replace(tzinfo=timezone.utc)
data[k] = v.isoformat()
# expose note explicitly for UI (prefer payload.note then description)
payload = data.get("payload") or {}
data["note"] = payload.get("note") or data.get("description") or ""