fix: 强化工作流与插件运行状态处理
- 显式传播工作流缓存故障并补充仓储测试 - 防止状态轮询重入和过期响应,规范执行记录无权限响应
This commit is contained in:
@@ -137,7 +137,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,
|
||||
@@ -146,27 +149,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('/api/v1/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('/api/v1/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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user