缩短装柜完成等待并保留权威状态查询
This commit is contained in:
@@ -46,6 +46,27 @@ export function shouldReconcileCompletion(error = {}) {
|
||||
return Boolean(error.network || error.timeout || code === 'TIMEOUT' || code === 'REQUEST_TIMEOUT')
|
||||
}
|
||||
|
||||
/** 受理后立即查询真实任务,串行短轮询只等待终态,不重发完成命令。 */
|
||||
export async function observeLoadingCompletion({ initialTask, readTask, isActive, onTask,
|
||||
intervalMs = 250, maxWaitMs = 10000, now = Date.now,
|
||||
wait = (delay) => new Promise((resolve) => setTimeout(resolve, delay)) }) {
|
||||
const started = now()
|
||||
let task = initialTask
|
||||
const phase = () => resolveCompletionPhase({ taskStatus: task?.taskStatus || task?.workflowStatus,
|
||||
commandStatus: task?.completionCommand?.status || task?.commandStatus })
|
||||
while (phase() === COMPLETION_PHASE.PROCESSING && isActive() && now() - started < maxWaitMs) {
|
||||
const latest = await readTask()
|
||||
if (!isActive()) return null
|
||||
if (!latest) throw new Error('服务端未返回装柜完成状态,请刷新任务')
|
||||
task = latest
|
||||
onTask(task)
|
||||
if (phase() !== COMPLETION_PHASE.PROCESSING) break
|
||||
const remaining = maxWaitMs - (now() - started)
|
||||
if (remaining > 0) await wait(Math.min(intervalMs, remaining))
|
||||
}
|
||||
return isActive() ? task : null
|
||||
}
|
||||
|
||||
/**
|
||||
* A retry keeps the original operationId and the exact accepted request facts.
|
||||
* expectedTaskVersion participates in requestHash and must not be refreshed.
|
||||
|
||||
Reference in New Issue
Block a user