进度(light透传): 把心跳已存的 current/total 交给前端,为客户端任务进度条打通服务端一段
客户端心跳一直在发 current/total,Java 也已存进 Redis 位置 Hash,但除判死豁免外没人读它, 所以客户端界面上解决风控/跟价这些任务画不出进度条。本次只在 light 出口上透传,不新建表、不写迁移。 - TaskProgressLightVo + progressCurrent/progressTotal/progressLabel(三个同生同灭) - 装配器只对非终态任务读位置;读不到或分母非正数一律留 null,由前端决定不画(0/0 会被读成"进度 0%",与"没有进度"是两件事) - 位置服务加 readDrawablePositions:单次轮询封顶 20 次 Redis 往返,按尝试次数计(老客户端一个都不发时命中数为 0 但往返数仍是全量) - 标签按「,」整段截到 60 字,定长硬切会截出半截店铺名 - 相似ASIN 那份私有 LightVo 同步(它是历史遗留的第二套实现,不同步会让该模块进度随轮询闪烁) - 顺带修该私有实现的投影缺陷:select 少 module_type 一列,真实查询下所有任务被判 missing, 与共享装配器 2026-09-14 那次线上事故同形态(那边有守卫测试、这份没有),现补守卫
This commit is contained in:
+7
@@ -20,4 +20,11 @@ public class SimilarAsinTaskLightVo {
|
||||
private Boolean fileReady;
|
||||
@Schema(description = "最后更新时间,ISO 本地时间字符串。", example = "2026-04-26T10:05:00")
|
||||
private String updatedAt;
|
||||
/** 客户端心跳上报的执行进度,三者同生同灭;无进度信息时全为 null(前端不画进度轨)。 */
|
||||
@Schema(description = "已处理数(客户端心跳上报;无进度信息时为 null)。", example = "12")
|
||||
private Integer progressCurrent;
|
||||
@Schema(description = "总处理单位数(相似ASIN 为待检测 ASIN 行数)。", example = "50")
|
||||
private Integer progressTotal;
|
||||
@Schema(description = "位置标签(中文,按「,」整段截短;无则为 null)。", example = "ASIN B0ABCD1234(12/50)")
|
||||
private String progressLabel;
|
||||
}
|
||||
|
||||
+28
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.exception.TaskOwnerMismatchException;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.task.TaskStatuses;
|
||||
import com.nanri.aiimage.common.util.LockSkipWitness;
|
||||
import com.nanri.aiimage.common.service.DistributedJobLockService;
|
||||
import com.nanri.aiimage.common.util.FailedStatusRowFilter;
|
||||
@@ -628,6 +629,7 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
Map<Long, FileTaskEntity> taskMap = new LinkedHashMap<>();
|
||||
for (FileTaskEntity task : fileTaskMapper.selectList(new LambdaQueryWrapper<FileTaskEntity>()
|
||||
.select(FileTaskEntity::getId,
|
||||
FileTaskEntity::getModuleType,
|
||||
FileTaskEntity::getStatus,
|
||||
FileTaskEntity::getUpdatedAt)
|
||||
.in(FileTaskEntity::getId, normalizedIds))) {
|
||||
@@ -636,6 +638,15 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
}
|
||||
}
|
||||
Map<Long, TaskFileJobEntity> jobMap = taskFileJobService.findAssembleJobsByTaskIds(MODULE_TYPE, new ArrayList<>(taskMap.keySet()));
|
||||
List<Long> activeTaskIds = new ArrayList<>();
|
||||
for (Long taskId : normalizedIds) {
|
||||
FileTaskEntity active = taskMap.get(taskId);
|
||||
if (active != null && !TaskStatuses.FileTask.TERMINAL.contains(active.getStatus())) {
|
||||
activeTaskIds.add(taskId);
|
||||
}
|
||||
}
|
||||
Map<Long, TaskHeartbeatPositionService.Position> positions =
|
||||
taskHeartbeatPositionService.readDrawablePositions(activeTaskIds);
|
||||
for (Long taskId : normalizedIds) {
|
||||
FileTaskEntity task = taskMap.get(taskId);
|
||||
if (task == null) {
|
||||
@@ -653,11 +664,28 @@ public class SimilarAsinTaskService implements SimilarAsinPipelineHost {
|
||||
item.setFileStatus(job == null ? null : job.getStatus());
|
||||
item.setFileError(job == null ? null : job.getErrorMessage());
|
||||
item.setUpdatedAt(fmt(task.getUpdatedAt()));
|
||||
fillProgressFromHeartbeat(item, positions.get(taskId));
|
||||
vo.getItems().add(item);
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 透传客户端心跳上报的处理位置,让相似ASIN 的 light 轮询也能画进度条。
|
||||
*
|
||||
* <p>口径与共享 {@code TaskProgressLightAssembler} 一致:终态任务不读、读不到或分母非正数时
|
||||
* 三个字段一起留 null,由前端决定「不画」。(相似ASIN 的私有 LightVo 是历史遗留的第二份实现,
|
||||
* 两边行为必须同步,否则这一模块的进度条会跟着轮询闪烁。)
|
||||
*/
|
||||
private void fillProgressFromHeartbeat(SimilarAsinTaskLightVo item, TaskHeartbeatPositionService.Position drawable) {
|
||||
if (drawable == null) {
|
||||
return;
|
||||
}
|
||||
item.setProgressCurrent(drawable.current());
|
||||
item.setProgressTotal(drawable.total());
|
||||
item.setProgressLabel(drawable.label());
|
||||
}
|
||||
|
||||
public SimilarAsinTaskBatchVo progressBatch(List<Long> taskIds) {
|
||||
SimilarAsinTaskBatchVo vo = new SimilarAsinTaskBatchVo();
|
||||
List<Long> requestedIds = taskIds == null ? List.of() : taskIds.stream()
|
||||
|
||||
Reference in New Issue
Block a user