修复运行日志复核发现的任务控制与结果误判
This commit is contained in:
+4
-6
@@ -92,19 +92,17 @@ def last_progress_epoch(path):
|
||||
return last
|
||||
|
||||
|
||||
def log_stalls(path):
|
||||
def log_stalls(path, now=None):
|
||||
"""统计日志尾部的卡死信号, 达到阈值的返回 {名称: 次数}。"""
|
||||
lines = tail(path, ERROR_SCAN_LINES)
|
||||
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}
|
||||
|
||||
# 无进展判据: 用日志自身的最后写入时间当"现在", 避免与调用方时钟不一致
|
||||
# 必须随真实时间推进: 进程卡住不再写日志时, mtime 也会冻结。
|
||||
# 离线复核历史日志时可显式传入当时的 now。
|
||||
progress = last_progress_epoch(path)
|
||||
if progress is not None:
|
||||
try:
|
||||
idle = os.path.getmtime(path) - progress
|
||||
except OSError:
|
||||
idle = 0
|
||||
idle = (time.time() if now is None else now) - progress
|
||||
if idle >= STALL_NO_PROGRESS_S:
|
||||
stalls['no_progress'] = int(idle)
|
||||
return stalls
|
||||
|
||||
Reference in New Issue
Block a user