fix(jd-publish): 重试复位后带回直推载荷+克隆缺源身份文案分档——35147 重试实录三件

This commit is contained in:
2026-11-21 14:23:47 +08:00
parent c59296da72
commit 4261103e31
9 changed files with 189 additions and 9 deletions
@@ -27,6 +27,7 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -291,6 +292,40 @@ class TaskClientPullServiceTest {
"30 分钟的让位窗口必须比 2 分钟的基础窗口更早,否则 Linux 会抢在本地客户端前面双跑");
}
/**
* 重试复位后的「页面直推」载荷(2026-11-21 任务 35147 实录):重试只复位(FAILED→PENDING)
* 不推送时任务停在 PENDING——兜底拉取开关默认关闭,PENDING 不再按时间判死,重试就是石沉大海。
* 通用重试端点经本方法把载荷带回给前端推桥;直推载荷不带 claimed(客户端照常 activate)。
*/
@Test
void 重试复位后按SPI带回直推载荷() {
FileTaskEntity row = task(33L, "JD_PUBLISH");
when(fileTaskMapper.selectById(33L)).thenReturn(row);
Map<String, Object> push = Map.of("type", "jd-product-publish-run", "data", Map.of("taskId", 33));
TaskClientPullService service = service(
new StubHandler("JD_PUBLISH", payload("jd-product-publish-run"), push, null));
Map<String, Object> result = service.buildQueuePushPayloadAfterRetry(33L);
assertEquals(push, result, "直推载荷让前端推回队列,客户端认领执行代;claimed 是兜底拉取专用,不在直推语义里");
}
@Test
void 无SPI或组装失败的任务重试后不带直推载荷且不影响复位() {
when(fileTaskMapper.selectById(77L)).thenReturn(task(77L, "APPEARANCE_PATENT"));
when(fileTaskMapper.selectById(78L)).thenReturn(task(78L, "SIMILAR_ASIN"));
when(fileTaskMapper.selectById(79L)).thenReturn(task(79L, "SIMILAR_ASIN"));
StubHandler broken = new StubHandler("SIMILAR_ASIN", payload("similar-asin-run"), null,
new IllegalStateException("boom"));
TaskClientPullService service = service(broken);
assertNull(service.buildQueuePushPayloadAfterRetry(null));
assertNull(service.buildQueuePushPayloadAfterRetry(0L));
assertNull(service.buildQueuePushPayloadAfterRetry(999L), "任务不存在时返回 null,不抛");
assertNull(service.buildQueuePushPayloadAfterRetry(77L), "无 SPI 的模块(Linux 执行)不走直推");
assertNull(service.buildQueuePushPayloadAfterRetry(78L), "载荷组装失败只降级为不推送,不给重试添堵");
}
private void stubPullCandidates(FileTaskEntity... rows) {
when(fileTaskMapper.selectLocalChannelPendingTasks(any(), any(), any(), any(), any(), anyInt(),
org.mockito.ArgumentMatchers.anyBoolean()))
@@ -387,17 +422,24 @@ class TaskClientPullServiceTest {
private final String moduleType;
private final Map<String, Object> queuePayload;
private final Map<String, Object> pushPayload;
private final RuntimeException failure;
private int buildCalls;
private int claimedCalls;
StubHandler(String moduleType, Map<String, Object> queuePayload) {
this(moduleType, queuePayload, null);
this(moduleType, queuePayload, null, null);
}
StubHandler(String moduleType, Map<String, Object> queuePayload, RuntimeException failure) {
this(moduleType, queuePayload, null, failure);
}
StubHandler(String moduleType, Map<String, Object> queuePayload,
Map<String, Object> pushPayload, RuntimeException failure) {
this.moduleType = moduleType;
this.queuePayload = queuePayload;
this.pushPayload = pushPayload;
this.failure = failure;
}
@@ -415,6 +457,14 @@ class TaskClientPullServiceTest {
return queuePayload;
}
@Override
public Map<String, Object> buildQueuePushPayload(FileTaskEntity task) {
if (failure != null) {
throw failure;
}
return pushPayload;
}
@Override
public void onClaimed(FileTaskEntity task) {
claimedCalls++;