fix: 强化工作流与插件运行状态处理
- 显式传播工作流缓存故障并补充仓储测试 - 防止状态轮询重入和过期响应,规范执行记录无权限响应
This commit is contained in:
@@ -44,7 +44,10 @@ const pollingNodes = ref<any[]>([]);
|
||||
const executeId = ref('');
|
||||
const pollingData = ref<any>({ nodes: {} });
|
||||
const initSignal = ref(false);
|
||||
const pollingTimer = ref<null | ReturnType<typeof setInterval>>(null);
|
||||
const POLLING_INTERVAL_MS = 1000;
|
||||
const pollingTimer = ref<null | ReturnType<typeof setTimeout>>(null);
|
||||
let pollingActive = false;
|
||||
let pollingGeneration = 0;
|
||||
const activeIndex = ref('1');
|
||||
const dialogContentKey = ref(0);
|
||||
const dialogPreparing = ref(false);
|
||||
@@ -237,42 +240,55 @@ function handleWorkflowSubmit(runParams: any) {
|
||||
|
||||
function startPolling(nextExecuteId: string) {
|
||||
stopPolling();
|
||||
pollingTimer.value = setInterval(() => {
|
||||
executePolling(nextExecuteId);
|
||||
}, 1000);
|
||||
pollingActive = true;
|
||||
pollingGeneration += 1;
|
||||
schedulePolling(nextExecuteId, pollingGeneration);
|
||||
}
|
||||
|
||||
function schedulePolling(nextExecuteId: string, generation: number) {
|
||||
pollingTimer.value = setTimeout(() => {
|
||||
pollingTimer.value = null;
|
||||
void executePolling(nextExecuteId, generation);
|
||||
}, POLLING_INTERVAL_MS);
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
pollingActive = false;
|
||||
pollingGeneration += 1;
|
||||
if (pollingTimer.value) {
|
||||
clearInterval(pollingTimer.value);
|
||||
clearTimeout(pollingTimer.value);
|
||||
pollingTimer.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
function executePolling(nextExecuteId: string) {
|
||||
api
|
||||
.post('/api/v1/pluginItem/testChainStatus', {
|
||||
async function executePolling(nextExecuteId: string, generation: number) {
|
||||
try {
|
||||
const res = await api.post('/api/v1/pluginItem/testChainStatus', {
|
||||
executeId: nextExecuteId,
|
||||
nodes: pollingNodes.value,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.errorCode !== 0) {
|
||||
return;
|
||||
}
|
||||
const nextData = {
|
||||
...res.data,
|
||||
nodes: res.data?.nodes || {},
|
||||
};
|
||||
pollingData.value = nextData;
|
||||
runResultResponse.value = nextData;
|
||||
if (nextData.status !== 1) {
|
||||
stopPolling();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
stopPolling();
|
||||
runResultResponse.value = buildErrorResult(error);
|
||||
});
|
||||
if (!pollingActive || generation !== pollingGeneration) return;
|
||||
if (res.errorCode !== 0) {
|
||||
stopPolling();
|
||||
return;
|
||||
}
|
||||
|
||||
const nextData = {
|
||||
...res.data,
|
||||
nodes: res.data?.nodes || {},
|
||||
};
|
||||
pollingData.value = nextData;
|
||||
runResultResponse.value = nextData;
|
||||
if (nextData.status !== 1) {
|
||||
stopPolling();
|
||||
return;
|
||||
}
|
||||
schedulePolling(nextExecuteId, generation);
|
||||
} catch (error) {
|
||||
if (!pollingActive || generation !== pollingGeneration) return;
|
||||
stopPolling();
|
||||
runResultResponse.value = buildErrorResult(error);
|
||||
}
|
||||
}
|
||||
|
||||
function resumeChain(payload: any) {
|
||||
|
||||
@@ -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