修复运行日志复核发现的任务控制与结果误判

Browse Source
This commit is contained in:
yws
2026-10-22 00:55:35 +00:00
parent 4e5d63ac6c
commit 625fdcd250
12 changed files with 384 additions and 93 deletions
+4 -6
View File
@@ -92,19 +92,17 @@ def last_progress_epoch(path):
return last return last
def log_stalls(path): def log_stalls(path, now=None):
"""统计日志尾部的卡死信号, 达到阈值的返回 {名称: 次数}。""" """统计日志尾部的卡死信号, 达到阈值的返回 {名称: 次数}。"""
lines = tail(path, ERROR_SCAN_LINES) lines = tail(path, ERROR_SCAN_LINES)
counts = {name: sum(marker in line for line in lines) for name, marker in STALL_MARKERS.items()} counts = {name: sum(marker in line for line in lines) for name, marker in STALL_MARKERS.items()}
stalls = {name: n for name, n in counts.items() if n >= STALL_THRESHOLD} stalls = {name: n for name, n in counts.items() if n >= STALL_THRESHOLD}
# 无进展判据: 用日志自身的最后写入时间当"现在", 避免与调用方时钟不一致 # 必须随真实时间推进: 进程卡住不再写日志时, mtime 也会冻结。
# 离线复核历史日志时可显式传入当时的 now。
progress = last_progress_epoch(path) progress = last_progress_epoch(path)
if progress is not None: if progress is not None:
try: idle = (time.time() if now is None else now) - progress
idle = os.path.getmtime(path) - progress
except OSError:
idle = 0
if idle >= STALL_NO_PROGRESS_S: if idle >= STALL_NO_PROGRESS_S:
stalls['no_progress'] = int(idle) stalls['no_progress'] = int(idle)
return stalls return stalls