fix(lastleg): pace master data pages without holding collection leases

This commit is contained in:
2026-10-14 16:56:40 +08:00
parent 63883f4ffd
commit 1112d11c80
4 changed files with 26 additions and 5 deletions
@@ -37,8 +37,8 @@ public class SelfopMasterDataCollector {
SelfopCollectionPolicy.requireBusiness(task);SelfopCollectionPolicy.requireBusiness(run);
require("MASTER_DATA".equals(task.getTaskType())&&lease.account(),"SELFOP_MASTER_TASK_REQUIRED");
var manifest=task.getRoutingManifestJson()==null?new Manifest():read(task.getRoutingManifestJson(),Manifest.class);
// Re-read priority after at most five pages, without losing the batch or consuming a failed attempt.
for(int slice=0;slice<5;slice++) {
// Master-data endpoints need slower paging than outbound. Yield every page so waiting never owns the account lease.
{
leases.renew(lease);boolean owners=!manifest.isOwnersComplete();int size=owners?1000:100;
var context=SelfopRequestContext.forTask(task,run,config);
LingxingAnalyticsClient.Page<?> page=owners?client.customers(context,manifest.nextPage,size):client.products(context,manifest.nextPage,size);
@@ -188,7 +188,8 @@ public class SelfopTaskService {
lockBusinessAccount(taskId);leases.verify(lease);
guardBeforeTaskLock(taskId);
var now=utcNow();var task=locks.lockTask(taskId);var run=locks.lockRun(runId);checkRunLease(task,run,lease);requireBusiness(task);requireBusiness(run);SelfopProgressProjection.freezeRun(task,run);run.setStatus("YIELDED");run.setFinishedAtUtc(now);run.setUpdatedAt(now);runs.updateById(run);
task.setStatus("RETRY_WAIT");task.setNextRetryAtUtc(now.plusSeconds(1));task.setUpdatedAt(now);tasks.updateById(task);
// Persist the master-data pacing across restarts; ordinary sales/inventory scheduling stays unchanged.
task.setStatus("RETRY_WAIT");task.setNextRetryAtUtc(now.plusSeconds("MASTER_DATA".equals(task.getTaskType())?5:1));task.setUpdatedAt(now);tasks.updateById(task);
}
@Transactional(noRollbackFor=BusinessSessionStoppedException.class)
public void fail(long taskId,long runId,String code,boolean retryable,SelfopLeaseService.Lease lease) {