fix(外观专利/品牌任务): 判死任务不再显示"结果生成中",批次心跳与进度取大写入防误杀
29473/29479 心跳超时判死后,前端 statusText/statusClass 先判 isResultPreparing 再看 FAILED,用户看到的是"结果生成中",会以为任务还在跑而继续等(后台检测可能确实还在跑、 文件生成后下载按钮照常出现,但文案必须是失败)。改成 FAILED 一律优先判定, pendingResultHint 也随之切成"任务已失败,结果文件…"。 后端两处心跳:外观专利 LLM 每批 touchJavaSideTaskActivity —— 软恢复后的检测阶段可达 数小时,不刷会被通用兜底线的 updated_at 超 120 分钟误杀;品牌进度改走 Redis Lua 合并 写入,phase 不被 crawling 打回(assembling/uploading/failed 受保护)、 current_line/total_lines 只增不减,消掉多执行方互相覆盖。
This commit is contained in:
+2
@@ -958,6 +958,8 @@ public class AppearancePatentTaskService {
|
||||
log.info("[appearance-patent] llm batch done taskId={} jobId={} rows={} batch={}/{} costMs={}",
|
||||
task.getId(), job.getId(), batchRows.size(), batchIndex, batchTotal,
|
||||
System.currentTimeMillis() - startedAt);
|
||||
// 每批刷新任务心跳:软恢复后的检测阶段可达数小时,不刷会被通用兜底线按 updated_at 超 120 分钟误杀(2026-09-28 29473/29479)
|
||||
touchJavaSideTaskActivity(task.getId());
|
||||
batchIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public class BrandTaskController {
|
||||
- line_progress.has_progress:当前是否存在 Redis 实时进度;
|
||||
- line_progress.info.file_index / file_total:当前处理到第几个文件 / 总文件数;
|
||||
- line_progress.info.file_name:当前处理文件名;
|
||||
- line_progress.info.current_line / total_lines:当前文件已处理行数 / 总行数;
|
||||
- line_progress.info.current_line / total_lines:任务级已处理品牌数 / 品牌总数(心跳按数据量上报,只增不减);
|
||||
- line_progress.info.phase:当前阶段,可能为 crawling / assembling / uploading / failed。
|
||||
|
||||
典型用途:
|
||||
|
||||
+45
-17
@@ -39,13 +39,18 @@ public class BrandTaskProgressCacheService {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分片结果落进度缓存:只写「文件级」字段(当前文件 / 已完文件数)与存活时间戳。
|
||||
*
|
||||
* <p>current_line / total_lines 自 2026-09-28 起是「任务级品牌数」(由
|
||||
* {@link #touchHeartbeat} 单调写入),不在这里按单文件覆盖——多文件任务下
|
||||
* 单文件的行数会把任务级进度打回去(前端进度条按数据量展示)。
|
||||
*/
|
||||
public void saveProgressFromResult(Long taskId,
|
||||
String fileUrl,
|
||||
int fileIndex,
|
||||
int fileTotal,
|
||||
String fileName,
|
||||
int currentLine,
|
||||
int totalLines,
|
||||
int finishedFiles) {
|
||||
String key = buildKey(taskId);
|
||||
String now = String.valueOf(Instant.now().toEpochMilli());
|
||||
@@ -55,8 +60,6 @@ public class BrandTaskProgressCacheService {
|
||||
values.put("file_total", String.valueOf(Math.max(fileTotal, 0)));
|
||||
values.put("file_name", blankToEmpty(fileName));
|
||||
values.put("file_url", blankToEmpty(fileUrl));
|
||||
values.put("current_line", String.valueOf(Math.max(Math.min(currentLine, totalLines), 0)));
|
||||
values.put("total_lines", String.valueOf(Math.max(totalLines, 0)));
|
||||
values.put("finished_files", String.valueOf(Math.max(finishedFiles, 0)));
|
||||
values.put("updated_at", now);
|
||||
values.put("last_heartbeat_at", now);
|
||||
@@ -87,23 +90,48 @@ public class BrandTaskProgressCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 心跳合并写(原子):current_line / total_lines 只增不减,phase 不被 crawling 打回收尾阶段。
|
||||
*
|
||||
* <p>品牌任务的心跳由执行方(15126 服务进程)按任务级「已处理品牌数/品牌总数」上报,
|
||||
* 与结果回传、收尾阶段更新可能乱序到达;用 Lua 做「取大写入」,
|
||||
* 避免旧值/单文件值把已展示的进度打回去。ARGV 为空串表示本次不带该字段。
|
||||
*/
|
||||
private static final DefaultRedisScript<Long> HEARTBEAT_MERGE_SCRIPT = new DefaultRedisScript<>(
|
||||
"""
|
||||
local key = KEYS[1]
|
||||
local phase = ARGV[1]
|
||||
if phase ~= '' then
|
||||
local stored = redis.call('hget', key, 'phase')
|
||||
local protect = (stored == 'assembling' or stored == 'uploading' or stored == 'failed')
|
||||
if not (protect and phase == 'crawling') then
|
||||
redis.call('hset', key, 'phase', phase)
|
||||
end
|
||||
end
|
||||
local current = tonumber(ARGV[2])
|
||||
if current ~= nil then
|
||||
local cur = tonumber(redis.call('hget', key, 'current_line')) or 0
|
||||
if current > cur then redis.call('hset', key, 'current_line', current) end
|
||||
end
|
||||
local total = tonumber(ARGV[3])
|
||||
if total ~= nil then
|
||||
local tot = tonumber(redis.call('hget', key, 'total_lines')) or 0
|
||||
if total > tot then redis.call('hset', key, 'total_lines', total) end
|
||||
end
|
||||
redis.call('hset', key, 'updated_at', ARGV[4])
|
||||
redis.call('hset', key, 'last_heartbeat_at', ARGV[4])
|
||||
return 1
|
||||
""", Long.class);
|
||||
|
||||
public void touchHeartbeat(Long taskId, String phase, Integer current, Integer total) {
|
||||
String key = buildKey(taskId);
|
||||
String now = String.valueOf(Instant.now().toEpochMilli());
|
||||
Map<String, String> values = new LinkedHashMap<>();
|
||||
values.put("updated_at", now);
|
||||
values.put("last_heartbeat_at", now);
|
||||
if (phase != null && !phase.isBlank()) {
|
||||
values.put("phase", normalizePhase(phase));
|
||||
}
|
||||
if (current != null) {
|
||||
values.put("current_line", String.valueOf(Math.max(current, 0)));
|
||||
}
|
||||
if (total != null) {
|
||||
values.put("total_lines", String.valueOf(Math.max(total, 0)));
|
||||
}
|
||||
try {
|
||||
stringRedisTemplate.opsForHash().putAll(key, values);
|
||||
stringRedisTemplate.execute(HEARTBEAT_MERGE_SCRIPT, List.of(key),
|
||||
phase == null || phase.isBlank() ? "" : normalizePhase(phase),
|
||||
current == null ? "" : String.valueOf(Math.max(current, 0)),
|
||||
total == null ? "" : String.valueOf(Math.max(total, 0)),
|
||||
now);
|
||||
stringRedisTemplate.expire(key, ttl());
|
||||
} catch (Exception ex) {
|
||||
log.warn("[brand-progress-cache] touch heartbeat degraded taskId={} msg={}", taskId, ex.getMessage());
|
||||
|
||||
+1
-4
@@ -347,15 +347,12 @@ public class BrandTaskService {
|
||||
aggregate == null ? 0 : defaultInteger(aggregate.getTotalLines()));
|
||||
String fileName = blankToDefault(sourceFile.getOriginalFilename(), sourceFile.getFileUrl());
|
||||
int fileIndex = sourceIndexByUrl.getOrDefault(fileUrl, 0);
|
||||
int currentLine = aggregate == null ? 0 : defaultInteger(aggregate.getProcessedLineCount());
|
||||
int currentTotalLines = aggregate == null ? 0 : Math.max(defaultInteger(aggregate.getTotalLines()), currentLine);
|
||||
// current_line/total_lines(任务级品牌数)由执行方心跳写入,这里不再按单文件覆盖
|
||||
brandTaskProgressCacheService.saveProgressFromResult(taskId,
|
||||
fileUrl,
|
||||
fileIndex,
|
||||
totalCount,
|
||||
fileName,
|
||||
currentLine,
|
||||
currentTotalLines,
|
||||
finishedCount);
|
||||
updateTaskProgress(taskId, finishedCount, totalCount);
|
||||
saveBrandProgressSnapshot(taskId, STATUS_RUNNING, totalCount, finishedCount, 0, null);
|
||||
|
||||
Reference in New Issue
Block a user