fix: 强化工作流与插件运行状态处理

- 显式传播工作流缓存故障并补充仓储测试

- 防止状态轮询重入和过期响应,规范执行记录无权限响应
This commit is contained in:
2026-07-27 19:40:40 +08:00
parent 567fd12706
commit 2892a7eddc
6 changed files with 351 additions and 58 deletions

View File

@@ -136,7 +136,10 @@ function submitV2() {
}
});
}
const timer = ref();
const POLLING_INTERVAL_MS = 1000;
const timer = ref<null | ReturnType<typeof setTimeout>>(null);
let pollingActive = false;
let pollingGeneration = 0;
const nodes = ref(
props.tinyFlowData.nodes.map((node: any) => ({
nodeId: node.id,
@@ -145,27 +148,46 @@ const nodes = ref(
);
// 轮询执行结果
function startPolling(executeId: any) {
if (timer.value) return;
timer.value = setInterval(() => executePolling(executeId), 1000);
if (pollingActive) return;
pollingActive = true;
pollingGeneration += 1;
schedulePolling(executeId, pollingGeneration);
}
function executePolling(executeId: any) {
api
.post('/userCenter/workflow/getChainStatus', {
function schedulePolling(executeId: any, generation: number) {
timer.value = setTimeout(() => {
timer.value = null;
void executePolling(executeId, generation);
}, POLLING_INTERVAL_MS);
}
async function executePolling(executeId: any, generation: number) {
try {
const res = await api.post('/userCenter/workflow/getChainStatus', {
executeId,
nodes: nodes.value,
})
.then((res) => {
// 5 是挂起状态
if (res.data.status !== 1 || res.data.status === 5) {
stopPolling();
}
props.onAsyncExecute?.(res.data);
});
if (!pollingActive || generation !== pollingGeneration) return;
// 5 是挂起状态;所有非运行态都结束当前轮询。
if (res.data.status !== 1) {
stopPolling();
}
props.onAsyncExecute?.(res.data);
if (pollingActive && generation === pollingGeneration) {
schedulePolling(executeId, generation);
}
} catch (error) {
if (!pollingActive || generation !== pollingGeneration) return;
stopPolling();
console.error('工作流状态轮询失败', error);
}
}
function stopPolling() {
submitLoading.value = false;
pollingActive = false;
pollingGeneration += 1;
if (timer.value) {
clearInterval(timer.value);
clearTimeout(timer.value);
timer.value = null;
}
}