系统定时任务日志持久化:新增入库与后台查询
- 新增系统任务日志表 t_system_job_logs,持久化记录每次执行结果、摘要、耗时、详情JSON\n- SystemJobLoader 注册任务时增加执行包装器:成功/失败均写入数据库日志,失败后继续抛出保证运行态状态一致\n- 系统任务后台日志接口改为查询数据库日志(不再依赖仅内存的 async_job logs),解决重启后日志丢失问题\n- 保持前端日志字段兼容,接口返回映射为 time/level/message 结构
This commit is contained in:
@@ -94,12 +94,24 @@ def api_trigger_job(job_key: str):
|
||||
@system_jobs_bp.route("/api/jobs/<job_key>/logs", methods=["GET"])
|
||||
@login_required
|
||||
def api_job_logs(job_key: str):
|
||||
job_id = async_job.get_job_id_by_key(job_key)
|
||||
if not job_id:
|
||||
return jsonify({"success": True, "data": []})
|
||||
|
||||
server = current_app.dashboard_server
|
||||
limit = int(request.args.get("limit", 100))
|
||||
logs = async_job.get_job_logs(job_id, limit=limit)
|
||||
db_logs = server.system_job_db.get_job_logs(job_key, limit=limit)
|
||||
# 为了兼容前端既有表头(time/level/message),这里做一层字段映射。
|
||||
logs = []
|
||||
for row in db_logs:
|
||||
status = str(row.get("status") or "")
|
||||
level = "error" if status == "failed" else ("success" if status == "success" else "info")
|
||||
logs.append(
|
||||
{
|
||||
"time": row.get("triggered_at"),
|
||||
"level": level,
|
||||
"message": row.get("summary") or "",
|
||||
"status": status,
|
||||
"duration_ms": row.get("duration_ms"),
|
||||
"detail_json": row.get("detail_json") or {},
|
||||
}
|
||||
)
|
||||
return jsonify({"success": True, "data": logs})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user