fix(终态): 消掉第二套任务终态词表,并把判据从正则换成 AST
useTaskProgressLoop 的 DEFAULT_TERMINAL 只认 SUCCESS|FAILED,而 COMPLETED≡SUCCESS
(task-status-text 把两者都映射成「已完成」,看板 SUCCESS_STATUSES_ORDERED 也含两者)。
收到 COMPLETED 不退出的轮询会一直空转到瞬断预算耗尽——这形状先前在跟价与风控两页踩过。
唯一被这次改宽影响的页面是 BrandCollectDataTab(它不传 isTerminal);BrandPublishTab
传自己那份含 COMPLETED+CANCELLED 的判定,行为不变,已用单独一条钉子钉住。
判据原先是"变量名恰为 status"的源码正则,同形异名全 src 有 16 处抓不到,等于恒绿;
现在用 typescript(node_modules 里已有)做 AST 尺子,并把"旧正则对三条反例失明"写进断言。
ShopMatch 的 waitForScheduledTaskStageExit 等的是阶段不是任务终态,为此给骨架加了可选
exitOn,保住它原有语义、未知状态不会挂死。
口径更正:窄集合"全 src 应为 0"不成立——实测 20 处/8 文件是 fileStatus(结果文件维度)、
loop-run 带 STOPPED 的词表、显示与下载判定,不同维度不该混进一本账;改成迁移面硬 0 +
逐文件台账只许减。catch 同理:grep 'catch (' 的 292 数不到无绑定 catch {,AST 口径 295/84。
This commit is contained in:
@@ -532,15 +532,18 @@ async function waitForTaskTerminal(taskId: number) {
|
||||
transientBudget: 30,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 排期任务「等当前轮次跑完」:退出条件是**状态离开 RUNNING**,不是任务到终态——
|
||||
* SUCCESS/COMPLETED/FAILED 走终态收尾、SCHEDULED 表示已排到下一轮、其余任何状态都算本轮结束。
|
||||
* 所以这里给骨架传 exitOn 而不是往 terminal 里堆状态表(漏一个后端新状态就是永不退出的紧循环)。
|
||||
* 循环本体(disposed 优先、瞬断计数与退避)在骨架里;取数方式(重型 batch)、页内副作用与文案留在本页。
|
||||
*/
|
||||
async function waitForScheduledTaskStageExit(taskId: number) {
|
||||
let transientErrorCount = 0
|
||||
const maxTransientErrors = 30
|
||||
while (true) {
|
||||
if (disposed) return 'STOPPED'
|
||||
try {
|
||||
return waitForTaskTerminalShared({
|
||||
taskId,
|
||||
isDisposed: () => disposed,
|
||||
pollStatus: async () => {
|
||||
const batch = await getShopMatchTaskProgressBatch([taskId])
|
||||
if (transientErrorCount > 0) queuePushResult.value = `任务 ${taskId} 服务已恢复,继续等待当前轮次结束...`
|
||||
transientErrorCount = 0
|
||||
if ((batch.missingTaskIds || []).includes(taskId)) {
|
||||
removeTaskLocally(taskId)
|
||||
await refreshTaskViewsBestEffort()
|
||||
@@ -558,31 +561,34 @@ async function waitForScheduledTaskStageExit(taskId: number) {
|
||||
taskDetails.value[taskId] = status
|
||||
saveTaskDetailsToStorage()
|
||||
}
|
||||
if (!status || status === 'RUNNING') {
|
||||
await sleep(getPollIntervalMs())
|
||||
continue
|
||||
}
|
||||
if (isTaskTerminalStatus(status)) {
|
||||
removePollingTask(taskId)
|
||||
await refreshTaskViewsBestEffort()
|
||||
restoreScheduledDispatches()
|
||||
return status
|
||||
}
|
||||
if (status === 'SCHEDULED') {
|
||||
} else if (status === 'SCHEDULED') {
|
||||
stopPollingTask(taskId)
|
||||
restoreScheduledDispatches()
|
||||
return status
|
||||
}
|
||||
return status
|
||||
} catch (error) {
|
||||
if (!isTransientBackendError(error)) throw error
|
||||
transientErrorCount += 1
|
||||
if (transientErrorCount >= maxTransientErrors) throw new Error(`任务 ${taskId} 等待当前轮次结束超时,请稍后手动刷新查看状态`)
|
||||
queuePushResult.value = `任务 ${taskId} 运行中,正在等待当前轮次结束(${transientErrorCount}/${maxTransientErrors})...`
|
||||
if (transientErrorCount === 1 || transientErrorCount % 5 === 0) ElMessage.warning(`任务 ${taskId} 运行中,服务暂时不可用,正在自动重试`)
|
||||
await sleep(getPollIntervalMs())
|
||||
}
|
||||
}
|
||||
// 空串=还没出这一轮(骨架据此继续等);离开 RUNNING 一律交回状态原文,含本页不认识的状态
|
||||
return status && status !== 'RUNNING' ? status : ''
|
||||
},
|
||||
// 瞬断恢复提示由骨架在取数成功后统一发(原来也是取到批次后立刻发,措辞照旧)
|
||||
onRecovered: () => {
|
||||
queuePushResult.value = `任务 ${taskId} 服务已恢复,继续等待当前轮次结束...`
|
||||
},
|
||||
onTransient: (attempt, budget) => {
|
||||
queuePushResult.value = `任务 ${taskId} 运行中,正在等待当前轮次结束(${attempt}/${budget})...`
|
||||
if (attempt === 1 || attempt % 5 === 0) ElMessage.warning(`任务 ${taskId} 运行中,服务暂时不可用,正在自动重试`)
|
||||
},
|
||||
isTransient: isTransientBackendError,
|
||||
onBudgetExhausted: () => {
|
||||
throw new Error(`任务 ${taskId} 等待当前轮次结束超时,请稍后手动刷新查看状态`)
|
||||
},
|
||||
exitOn: (status) => status !== 'RUNNING',
|
||||
intervalMs: getPollIntervalMs,
|
||||
sleep,
|
||||
transientBudget: 30,
|
||||
})
|
||||
}
|
||||
function resolvedTaskStatus(item: ShopMatchHistoryItem) {
|
||||
const itemStatus = item.taskStatus || ''
|
||||
|
||||
Reference in New Issue
Block a user