|
|
|
|
@ -19,6 +19,7 @@ import {
|
|
|
|
|
updateCanvasDataMap,
|
|
|
|
|
resetNodeStatus,
|
|
|
|
|
updateIsRunning,
|
|
|
|
|
updateIsPaused,
|
|
|
|
|
updateEventListOld,
|
|
|
|
|
addRuntimeLog,
|
|
|
|
|
clearRuntimeLogs,
|
|
|
|
|
@ -39,7 +40,7 @@ import { appFLowHandle } from '@/pages/flowEditor/utils/appFlowhandle';
|
|
|
|
|
import { handelEventNodeList, updateEvent, upDatePublish } from '@/pages/flowEditor/utils/common';
|
|
|
|
|
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
import { getAppListBySceneId, runMainFlow, runSubFlow, stopApp } from '@/api/apps';
|
|
|
|
|
import { getAppListBySceneId, runMainFlow, runSubFlow, stopApp, pauseApp, resumeApp, reRunApp } from '@/api/apps';
|
|
|
|
|
import store from '@/store';
|
|
|
|
|
import { updateAppEvent, updateAppEventChannel, updateAppFlowData } from '@/api/appEvent';
|
|
|
|
|
import { getUrlParams, sleep } from '@/utils/common';
|
|
|
|
|
@ -1423,6 +1424,96 @@ export const useFlowCallbacks = (
|
|
|
|
|
}
|
|
|
|
|
}, [getCurrentAppKey]);
|
|
|
|
|
|
|
|
|
|
// 暂停/恢复应用
|
|
|
|
|
const handlePause = useCallback(async (isPaused: boolean) => {
|
|
|
|
|
const { currentAppData, appRuntimeData } = store.getState().ideContainer;
|
|
|
|
|
const appKey = getCurrentAppKey();
|
|
|
|
|
|
|
|
|
|
if (!currentAppData) {
|
|
|
|
|
Message.warning('请先选择一个应用');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取runId
|
|
|
|
|
const runId = appKey && appRuntimeData[appKey] ? appRuntimeData[appKey].runId : '';
|
|
|
|
|
|
|
|
|
|
if (!runId) {
|
|
|
|
|
Message.warning('应用未运行');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (isPaused) {
|
|
|
|
|
// 当前已暂停,执行恢复操作
|
|
|
|
|
const res: any = await resumeApp({ id: runId });
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Message.success('应用已恢复');
|
|
|
|
|
// 更新暂停状态为 false
|
|
|
|
|
dispatch(updateIsPaused(false));
|
|
|
|
|
} else {
|
|
|
|
|
Message.error(res.msg || '恢复失败');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 当前正在运行,执行暂停操作
|
|
|
|
|
const res: any = await pauseApp({ id: runId });
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Message.success('应用已暂停');
|
|
|
|
|
// 更新暂停状态为 true
|
|
|
|
|
dispatch(updateIsPaused(true));
|
|
|
|
|
} else {
|
|
|
|
|
Message.error(res.msg || '暂停失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('暂停/恢复失败:', error);
|
|
|
|
|
Message.error('操作失败');
|
|
|
|
|
}
|
|
|
|
|
}, [getCurrentAppKey]);
|
|
|
|
|
|
|
|
|
|
// 重跑应用
|
|
|
|
|
const handleReRun = useCallback(async () => {
|
|
|
|
|
const { currentAppData, appRuntimeData, socketId } = store.getState().ideContainer;
|
|
|
|
|
const appKey = getCurrentAppKey();
|
|
|
|
|
|
|
|
|
|
if (!currentAppData) {
|
|
|
|
|
Message.warning('请先选择一个应用');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取runId (instanceId)
|
|
|
|
|
const instanceId = appKey && appRuntimeData[appKey] ? appRuntimeData[appKey].runId : '';
|
|
|
|
|
|
|
|
|
|
if (!instanceId) {
|
|
|
|
|
Message.warning('应用未运行');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 判断是主流程还是子流程
|
|
|
|
|
const appId = currentAppData.key && currentAppData.key.includes('sub')
|
|
|
|
|
? currentAppData.parentAppId
|
|
|
|
|
: currentAppData.id;
|
|
|
|
|
|
|
|
|
|
const res: any = await reRunApp({
|
|
|
|
|
appId,
|
|
|
|
|
instanceId,
|
|
|
|
|
socketId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
Message.success('应用重跑成功');
|
|
|
|
|
|
|
|
|
|
// 重置节点状态
|
|
|
|
|
dispatch(resetNodeStatus());
|
|
|
|
|
} else {
|
|
|
|
|
Message.error(res.msg || '重跑失败');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('重跑失败:', error);
|
|
|
|
|
Message.error('重跑失败');
|
|
|
|
|
}
|
|
|
|
|
}, [getCurrentAppKey]);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
// Event handlers
|
|
|
|
|
onNodesChange,
|
|
|
|
|
@ -1456,7 +1547,9 @@ export const useFlowCallbacks = (
|
|
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
saveFlowDataToServer,
|
|
|
|
|
handleRun
|
|
|
|
|
handleRun,
|
|
|
|
|
handlePause,
|
|
|
|
|
handleReRun
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
export default useFlowCallbacks;
|