修复系统定时任务时间显示格式异常

变更项:1) 在 system_jobs 蓝图新增时间归一化方法,统一输出为 yyyy-MM-dd HH:mm:ss。2) 系统任务列表接口对 next_run_at 与 last_run_at 做后端格式化。3) 系统任务日志接口对 triggered_at 做后端格式化,避免出现 Fri, 17 Apr ... 的 RFC 时间串。4) 补充中文注释说明格式化策略。
This commit is contained in:
liuwei
2026-04-17 09:09:48 +08:00
parent 60cfcea1ad
commit 6b68de7f4e

View File

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from flask import Blueprint, current_app, jsonify, render_template, request
from utils.decorator.async_job import async_job
@@ -8,6 +9,18 @@ from .auth import login_required
system_jobs_bp = Blueprint("system_jobs", __name__, url_prefix="/system_jobs")
def _normalize_datetime_text(value):
"""统一时间文本格式为 `YYYY-MM-DD HH:MM:SS`。"""
if value is None:
return value
if isinstance(value, datetime):
return value.strftime("%Y-%m-%d %H:%M:%S")
text = str(value)
if "T" in text:
return text.replace("T", " ")[:19]
return text
@system_jobs_bp.route("/")
@login_required
def page_system_jobs():
@@ -38,11 +51,11 @@ def api_list_jobs():
"runtime_enabled": runtime.get("enabled"),
"running": runtime.get("running", False),
"trigger_text": runtime.get("trigger_text", ""),
"last_run_at": runtime.get("last_run_at"),
"last_run_at": _normalize_datetime_text(runtime.get("last_run_at")),
"last_status": runtime.get("last_status"),
"last_error": runtime.get("last_error"),
"last_duration_ms": runtime.get("last_duration_ms"),
"next_run_at": runtime.get("next_run_at"),
"next_run_at": _normalize_datetime_text(runtime.get("next_run_at")),
"run_count": runtime.get("run_count", 0),
"success_count": runtime.get("success_count", 0),
"fail_count": runtime.get("fail_count", 0),
@@ -104,7 +117,7 @@ def api_job_logs(job_key: str):
level = "error" if status == "failed" else ("success" if status == "success" else "info")
logs.append(
{
"time": row.get("triggered_at"),
"time": _normalize_datetime_text(row.get("triggered_at")),
"level": level,
"message": row.get("summary") or "",
"status": status,