提交 712feaa9 authored 作者: 陈泽健's avatar 陈泽健

fix(service-monitor): 所有时间戳统一使用北京时区

_now() 和 _run_job_body 中的 datetime.now() 改为
datetime.now(SHANGHAI_TZ),确保 last_run_at / created_at
等字段显示北京时间而非服务器 UTC 时间。
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
上级 1147566e
......@@ -142,7 +142,8 @@ def _save_schedules(schedules: list) -> None:
def _now() -> str:
return datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
"""返回当前北京时间字符串(所有时间戳统一使用北京时区)。"""
return datetime.now(SHANGHAI_TZ).strftime("%Y-%m-%dT%H:%M:%S")
def _calc_next_run(cron_expr: str) -> Optional[str]:
......@@ -493,7 +494,7 @@ def _run_job_body(schedule_id: str) -> None:
schedule_id,
status="success" if result.get("success") else "failed",
report_id=result.get("report_id", ""),
run_at=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
run_at=_now(),
)
_update_current_status(schedule_id, "success" if result.get("success") else "failed")
logger.info("定时任务执行完成: %s, report_id=%s", schedule_id, result.get("report_id"))
......@@ -503,7 +504,7 @@ def _run_job_body(schedule_id: str) -> None:
schedule_id,
status="error",
report_id="",
run_at=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
run_at=_now(),
)
_update_current_status(schedule_id, "error") # 与 last_run_status 一致
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论