fix(任务判死): 外观/货源判死文案按证据陈述,不再断言 Python 中断
2026-10-01 三条外观任务被心跳判死时一行业务结果都没回传过(Linux worker 一次领 5 条却只有 2 个采集槽,多出来的任务零心跳零分片直到钟面走完),而文案固定写 "Python interrupted before uploading final result",把「没开跑」说成「跑挂了」,排查方向被带偏过一次。现在按已落库分片数、 最后回传/心跳时间、客户端最后一次上报的位置分述;结果文件作业重试耗尽也不再写成客户端中断。
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.nanri.aiimage.common.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端型任务(外观专利 / 货源)心跳判死文案:只写证据支持的话。
|
||||
*
|
||||
* <p>历史上这里固定写 "Python interrupted before uploading final result",而 2026-10-01 线上三条
|
||||
* 外观任务其实一行业务结果都没回传过——Linux worker 一次领 5 条却只有 2 个采集槽,多出来的任务
|
||||
* 状态是 RUNNING、零心跳零分片,两小时后被写成「Python 中断」。「没开工」被说成「跑挂了」,
|
||||
* 排查方向被带偏过一次,故文案按证据分述,并把客户端最后一次上报的位置一起带出来
|
||||
* (排队中的任务会上报「排队等待空闲槽位」,与真在采集是两种成因)。
|
||||
*
|
||||
* @param chunkCount 已落库的结果分片数(biz_task_chunk)
|
||||
* @param lastChunkAt 最后一次结果分片回传时间,从未回传时为 null
|
||||
* @param lastHeartbeatAt 最后一次客户端心跳时间,Redis 无记录时为 null
|
||||
* @param lastProgress 客户端最后一次上报的位置/阶段文本,老客户端或无位置信息时为 null
|
||||
* @param fileJobExhausted 结果文件作业是否已重试耗尽(true 时责任不在客户端回传)
|
||||
* @param timeoutMinutes 判死阈值(分钟)
|
||||
*/
|
||||
public record StaleTaskDeathReason(long chunkCount,
|
||||
LocalDateTime lastChunkAt,
|
||||
LocalDateTime lastHeartbeatAt,
|
||||
String lastProgress,
|
||||
boolean fileJobExhausted,
|
||||
int timeoutMinutes) {
|
||||
|
||||
private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("MM-dd HH:mm");
|
||||
|
||||
public String describe() {
|
||||
if (chunkCount > 0 && fileJobExhausted) {
|
||||
return "已收到 " + chunkCount + " 个结果分片,但结果文件生成多次失败,任务已自动结束";
|
||||
}
|
||||
String headline = chunkCount <= 0L
|
||||
? "客户端未回传任何检测结果,超过 " + Math.max(1, timeoutMinutes) + " 分钟无进展"
|
||||
: "客户端回传中断";
|
||||
List<String> evidence = new ArrayList<>();
|
||||
if (chunkCount > 0L) {
|
||||
evidence.add("已收到 " + chunkCount + " 个分片,最后一次 " + at(lastChunkAt));
|
||||
}
|
||||
evidence.add("最后心跳 " + at(lastHeartbeatAt));
|
||||
if (lastProgress != null && !lastProgress.isBlank()) {
|
||||
evidence.add("最后上报 " + lastProgress.trim());
|
||||
}
|
||||
return headline + ",任务已自动结束(" + String.join(";", evidence) + ")";
|
||||
}
|
||||
|
||||
private static String at(LocalDateTime time) {
|
||||
return time == null ? "时间未知" : time.format(TIME);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user