fix(jd-publish): 重试复位后带回直推载荷+克隆缺源身份文案分档——35147 重试实录三件
This commit is contained in:
+7
@@ -48,4 +48,11 @@ public class JdPublishTaskPullSpiImpl implements ClientTaskPullSpi {
|
||||
log.info("[jd-publish] 兜底载荷已组装 taskId={}", task.getId());
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> buildQueuePushPayload(FileTaskEntity task) {
|
||||
// 页面直推语义:与建单响应同源、不带 claimed——重试复位后的任务仍是 PENDING,
|
||||
// 客户端必须走 activate 认领执行代(带 claimed 会跳过激活,服务端永远停在 PENDING)。
|
||||
return publishTaskService.buildQueuePayload(task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +63,11 @@ public class JdTaskPullSpiImpl implements ClientTaskPullSpi {
|
||||
create.getShopCategoryNames() == null ? 0 : create.getShopCategoryNames().size());
|
||||
return Map.of("type", QUEUE_TYPE, "data", data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> buildQueuePushPayload(FileTaskEntity task) {
|
||||
// 本实现的兜底载荷本就不带 claimed(采集客户端按登录身份自校验,无 activate 环节),
|
||||
// 重试直推与兜底拉取共用同一份组装,避免两处键集漂移。
|
||||
return buildQueuePayload(task);
|
||||
}
|
||||
}
|
||||
|
||||
+16
-3
@@ -2,6 +2,7 @@ package com.nanri.aiimage.modules.task.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.task.service.TaskClientPullService;
|
||||
import com.nanri.aiimage.modules.task.service.TaskInPlaceRetryService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -15,12 +16,19 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 失败任务重试(模块无关,2026-11-01 用户拍板)。
|
||||
*
|
||||
* <p>口径:失败任务不再自动克隆新任务(同一份输入会多出好几行结果),改由用户在
|
||||
* 「删除」旁点「重试」——在原任务上复位续跑,保留已收分片、解析载荷与已检测标记。
|
||||
* 外观专利另有模块专属端点 {@code /api/appearance-patent/tasks/{id}/retry},行为一致。
|
||||
*
|
||||
* <p>2026-11-21 起响应体带回「页面直推」queuePayload(实现了 {@code ClientTaskPullSpi}
|
||||
* 的本机执行类模块,如京东采集/上架):复位是 PENDING,前端把载荷推回 pywebview 队列
|
||||
* 客户端才会立刻认领——兜底拉取开关默认关闭,只复位不推送的任务会永远停在 PENDING
|
||||
* (35147 重试实录)。非本机执行模块 data 为 null,前端维持旧口径提示。
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -30,18 +38,23 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class TaskRetryController {
|
||||
|
||||
private final TaskInPlaceRetryService taskRetryService;
|
||||
private final TaskClientPullService clientPullService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
|
||||
@PostMapping("/{taskId}/retry")
|
||||
@Operation(summary = "重试失败任务",
|
||||
description = "在原任务上复位(FAILED→PENDING),保留分片/解析载荷/已检测标记,不创建新任务。")
|
||||
public ApiResponse<Void> retry(
|
||||
description = "在原任务上复位(FAILED→PENDING),保留分片/解析载荷/已检测标记,不创建新任务。"
|
||||
+ "本机执行类模块同时带回页面直推 queuePayload,前端推回 pywebview 队列。")
|
||||
public ApiResponse<Map<String, Object>> retry(
|
||||
@Parameter(description = "任务 ID。", required = true) @PathVariable Long taskId,
|
||||
@Parameter(description = "当前用户 ID,必须与任务归属一致。", required = true)
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
taskRetryService.retryFailedTask(taskId, userId);
|
||||
return ApiResponse.success(null);
|
||||
// 复位是 PENDING:把「页面直推」载荷(无 claimed,客户端照常 activate)一并带回,
|
||||
// 前端经桥推送客户端才会立刻认领;拿不到载荷时按旧口径提示,重试复位不受影响。
|
||||
Map<String, Object> queuePayload = clientPullService.buildQueuePushPayloadAfterRetry(taskId);
|
||||
return ApiResponse.success(queuePayload == null ? null : Map.of("queuePayload", queuePayload));
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -209,6 +209,34 @@ public class TaskClientPullService {
|
||||
return claimed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试复位后的「页面直推」载荷(无 claimed,客户端照常 activate):通用重试端点把它带回
|
||||
* 给前端,前端经 pywebview 桥推回本机队列——只复位不推的话任务停在 PENDING(兜底拉取
|
||||
* 开关默认关闭,PENDING 不再按时间判死,重试就是石沉大海;2026-11-21 任务 35147 实录)。
|
||||
* 模块无 SPI / 任务不存在 / 载荷组装失败一律返回 null,前端按旧口径提示「等客户端领取」,
|
||||
* 重试复位本身不受影响。
|
||||
*/
|
||||
public Map<String, Object> buildQueuePushPayloadAfterRetry(Long taskId) {
|
||||
if (taskId == null || taskId <= 0) {
|
||||
return null;
|
||||
}
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
ClientTaskPullSpi handler = pullHandlers.get(task.getModuleType());
|
||||
if (handler == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return handler.buildQueuePushPayload(task);
|
||||
} catch (Exception ex) {
|
||||
log.warn("[client-task-pull] 重试后组装直推载荷失败 taskId={} moduleType={} err={}",
|
||||
task.getId(), task.getModuleType(), ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 逐条原子认领候选任务并组装载荷;认领失败/载荷缺失的任务原样留给下一轮或标失败。 */
|
||||
private List<TaskClientPullVo> claimCandidates(List<FileTaskEntity> candidates, String scope) {
|
||||
List<TaskClientPullVo> claimed = new ArrayList<>();
|
||||
|
||||
@@ -27,6 +27,18 @@ public interface ClientTaskPullSpi {
|
||||
*/
|
||||
Map<String, Object> buildQueuePayload(FileTaskEntity task);
|
||||
|
||||
/**
|
||||
* 组装「页面直推」语义的载荷:失败任务在原任务上重试复位(FAILED→PENDING)后,前端经
|
||||
* pywebview 桥把它推回本机队列。与建单响应的载荷同形——<b>不带 claimed 标记</b>,
|
||||
* 客户端照常 activate 认领执行代;{@link #buildQueuePayload} 的 claimed 是兜底拉取
|
||||
* 专用(那条通道已把任务原子认领成 RUNNING,客户端凭它免激活),带进直推载荷会让
|
||||
* 客户端跳过 activate、服务端永远停在 PENDING(2026-11-21 任务 35147 重试实录)。
|
||||
* 默认 null=该模块不由本机客户端执行(重试后走原执行通道,前端不必推送)。
|
||||
*/
|
||||
default Map<String, Object> buildQueuePushPayload(FileTaskEntity task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 认领成功后的模块侧动作:对齐各自的 activate(多数模块实现为
|
||||
* {@code cacheService.touchTaskHeartbeat(taskId)},让页面立刻看到 RUNNING)。
|
||||
|
||||
Reference in New Issue
Block a user