fix(selfop): allow explicit retry of failed continuous inventory roots
This commit is contained in:
+37
@@ -506,6 +506,43 @@ class SelfopTaskServiceTest {
|
||||
service.fail(1L,20L,"SELFOP_STOCK_DUPLICATE",false,lease);
|
||||
assertThat(root.getStatus()).isEqualTo("DEAD");
|
||||
}
|
||||
@Test void commandRetriesDeadContinuousInventoryThroughRealTaskServiceAndRecordsAudit(){
|
||||
var root=continuousInventoryRoot();root.setStatus("DEAD");root.setAttemptCount(2);
|
||||
var failed=run("FAILED");failed.setErrorCode("SELFOP_STOCK_DUPLICATE");
|
||||
when(runs.selectOne(any())).thenReturn(failed);
|
||||
when(tasks.selectOne(any())).thenAnswer(inv->{var q=(QueryWrapper<?>)inv.getArgument(0);
|
||||
return q.getSqlSegment().contains("task_no")?root:null;});
|
||||
config.setSourceAccount("synthetic-account");config.getWarehouses().put("WH-A",new SelfopAnalyticsProperties.Warehouse());
|
||||
String budget=root.getBusinessBudgetJson();var planned=root.getPlannedAtUtc();
|
||||
var commands=new SelfopCommandService(service,scopes,accounts,config,tasks);
|
||||
var command=new SelfopCommandService.Command("recover-stock","WH-A","RETRY",root.getTaskNo(),null,null,null,null,"retry completed unstable inventory scan");
|
||||
assertThat(commands.request(command,"operator")).isSameAs(root);
|
||||
assertThat(root.getStatus()).isEqualTo("READY");assertThat(root.getAttemptCount()).isEqualTo(2);
|
||||
assertThat(root.getBusinessBudgetJson()).isEqualTo(budget);assertThat(root.getPlannedAtUtc()).isEqualTo(planned);
|
||||
assertThat(root.getRequestedBy()).isEqualTo(SelfopCollectionPolicy.CONTINUOUS_PLANNER);
|
||||
var order=inOrder(tasks);order.verify(tasks).updateById(root);
|
||||
order.verify(tasks).insert(argThat((SelfopSyncTask audit)->"MANUAL_RETRY".equals(audit.getTaskType())
|
||||
&&"SUCCEEDED".equals(audit.getStatus())&&Long.valueOf(1).equals(audit.getUpstreamTaskId())
|
||||
&&Long.valueOf(1).equals(audit.getBusinessRootTaskId())));
|
||||
}
|
||||
@Test void explicitInventoryRetryCannotClearPersistedStopOrRetryUnknownFailure(){
|
||||
for(String error:List.of("LINGXING_WMS_RATE_LIMITED","INTEGRATION_TRANSPORT_FAILURE","SELFOP_EXECUTION_FAILED")){
|
||||
var root=continuousInventoryRoot();root.setStatus("DEAD");String budget=root.getBusinessBudgetJson();
|
||||
var failed=run("FAILED");failed.setErrorCode(error);when(runs.selectOne(any())).thenReturn(failed);
|
||||
assertThatThrownBy(()->service.retry(1L,"retry-protected","operator","offline retry"))
|
||||
.isInstanceOf(SelfopTaskService.BusinessSessionStoppedException.class);
|
||||
assertThat(root.getStatus()).isEqualTo("DEAD");assertThat(root.getBusinessBudgetJson()).isEqualTo(budget);
|
||||
}
|
||||
var root=continuousInventoryRoot();root.setStatus("DEAD");
|
||||
var budget=read(root.getBusinessBudgetJson(),com.baiyue.lastleg.selfoperated.analytics.request.SelfopBusinessBudget.class);
|
||||
budget.stopReason="BUSINESS_SESSION_STOPPED";root.setBusinessBudgetJson(json(budget));String frozen=root.getBusinessBudgetJson();
|
||||
var failed=run("FAILED");failed.setErrorCode("SELFOP_STOCK_DUPLICATE");when(runs.selectOne(any())).thenReturn(failed);
|
||||
assertThatThrownBy(()->service.retry(1L,"retry-stopped","operator","offline retry"))
|
||||
.isInstanceOf(SelfopTaskService.BusinessSessionStoppedException.class);
|
||||
assertThat(root.getBusinessBudgetJson()).isEqualTo(frozen);
|
||||
verify(tasks,never()).updateById(any(SelfopSyncTask.class));verify(tasks,never()).insert(any(SelfopSyncTask.class));
|
||||
verify(tasks,never()).update(any(),any());
|
||||
}
|
||||
private SelfopSyncTask continuousInventoryRoot(){
|
||||
var root=boundedRoot(0,utcNow().plusMinutes(3));config.setContinuousBusinessCollectionEnabled(true);
|
||||
root.setTaskType("SCHEDULED");root.setStatus("RUNNING");root.setApplyState("NOT_APPLICABLE");
|
||||
|
||||
Reference in New Issue
Block a user