waiting webhoo fix

This commit is contained in:
Michael Kret 2024-09-16 10:53:04 +03:00
parent d34cabddd3
commit 139d481aac
2 changed files with 49 additions and 35 deletions

View file

@ -313,7 +313,6 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
const { webhookSuffix } = (node.parameters.options ?? {}) as IDataObject;
const suffix = webhookSuffix && typeof webhookSuffix !== 'object' ? `/${webhookSuffix}` : '';
const testUrl = `${rootStore.formWaitingUrl}/${executionId}${suffix}`;
console.log(testUrl);
openPopUpWindow(testUrl);
}
@ -323,42 +322,57 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
nodeData?: ITaskData;
source?: string;
}): Promise<IExecutionPushResponse | undefined> {
const runWorkflowApiResponse = await runWorkflow(options);
let runWorkflowApiResponse = await runWorkflow(options);
let { executionId } = runWorkflowApiResponse || {};
if (runWorkflowApiResponse && runWorkflowApiResponse.executionId) {
const shownForms: string[] = [];
while (true) {
const execution = await workflowsStore.getExecution(runWorkflowApiResponse.executionId);
if (!execution || workflowsStore.workflowExecutionData === null) break;
// execution waiting for webhook
while (!executionId) {
await useExternalHooks().run('workflowRun.runWorkflow', {
nodeName: options.destinationNode,
source: options.source,
});
if (execution.finished) {
workflowsStore.setWorkflowExecutionData(execution);
nodeHelpers.updateNodesExecutionIssues();
break;
}
await sleep(2000);
if (execution.data) {
workflowsStore.setWorkflowExecutionRunData(execution.data);
}
if (execution.status === 'waiting') {
const { lastNodeExecuted } = execution.data?.resultData || {};
const waitingNode = workflowsStore.getNodeByName(lastNodeExecuted || '');
if (
waitingNode &&
waitingNode.type === WAIT_NODE_TYPE &&
waitingNode.parameters.resume === 'form' &&
!shownForms.includes(waitingNode.name)
) {
openWaitNodeFormResumeUrl(waitingNode, runWorkflowApiResponse.executionId);
shownForms.push(waitingNode.name);
}
}
await sleep(2000);
if (workflowsStore.activeExecutionId) {
executionId = workflowsStore.activeExecutionId;
runWorkflowApiResponse = { executionId };
}
}
const shownForms: string[] = [];
while (true) {
const execution = await workflowsStore.getExecution(executionId);
if (!execution || workflowsStore.workflowExecutionData === null) break;
if (execution.finished) {
workflowsStore.setWorkflowExecutionData(execution);
nodeHelpers.updateNodesExecutionIssues();
break;
}
if (execution.data) {
workflowsStore.setWorkflowExecutionRunData(execution.data);
}
if (execution.status === 'waiting') {
const { lastNodeExecuted } = execution.data?.resultData || {};
const waitingNode = workflowsStore.getNodeByName(lastNodeExecuted || '');
if (
waitingNode &&
waitingNode.type === WAIT_NODE_TYPE &&
waitingNode.parameters.resume === 'form' &&
!shownForms.includes(waitingNode.name)
) {
openWaitNodeFormResumeUrl(waitingNode, executionId);
shownForms.push(waitingNode.name);
}
}
await sleep(2000);
}
await useExternalHooks().run('workflowRun.runWorkflow', {
nodeName: options.destinationNode,
source: options.source,

View file

@ -76,15 +76,15 @@ export const openPopUpWindow = (
const windowWidth = window.innerWidth;
const smallScreen = windowWidth <= 800;
if (options?.alwaysInNewTab || smallScreen) {
window.open(url, '_blank');
return window.open(url, '_blank');
} else {
const height = options?.width || 700;
const width = options?.height || window.innerHeight - 50;
const left = (window.innerWidth - height) / 2;
const top = 50;
const features = `width=${height},height=${width},left=${left},top=${top},resizable=yes,scrollbars=yes`;
window.open(url, '_blank', features);
const windowName = `form-waiting-since-${Date.now()}`;
return window.open(url, windowName, features);
}
};
@ -141,7 +141,7 @@ export function displayForm({
const { webhookSuffix } = (node.parameters.options ?? {}) as IDataObject;
const suffix =
webhookSuffix && typeof webhookSuffix !== 'object' ? `/${webhookSuffix}` : '';
testUrl = `${formWaitingUrl}/${executionId}${suffix}`;
console.log(`${formWaitingUrl}/${executionId}${suffix}`);
}
if (testUrl && source !== 'RunData.ManualChatMessage') openPopUpWindow(testUrl);