Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Execute Workflow Node): Add 'Wait For Sub-Workflow Completion' option #8389

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 52 additions & 12 deletions packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ export class ExecuteWorkflow implements INodeType {
],
default: 'once',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
default: {},
placeholder: 'Add Option',
options: [
{
displayName: 'Wait For Sub-Workflow Completion',
name: 'waitForSubWorkflow',
type: 'boolean',
default: true,
description:
'Whether the main workflow should wait for the sub-workflow to complete its execution before proceeding',
},
],
},
],
};

Expand All @@ -179,25 +196,37 @@ export class ExecuteWorkflow implements INodeType {
const items = this.getInputData();

if (mode === 'each') {
const returnData: INodeExecutionData[][] = [];
let returnData: INodeExecutionData[][] = [];

for (let i = 0; i < items.length; i++) {
try {
const waitForSubWorkflow = this.getNodeParameter(
'options.waitForSubWorkflow',
i,
true,
) as boolean;
const workflowInfo = await getWorkflowInfo.call(this, source, i);
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(workflowInfo, [
items[i],
]);

for (const [outputIndex, outputData] of workflowResult.entries()) {
for (const item of outputData) {
item.pairedItem = { item: i };
}
if (waitForSubWorkflow) {
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(
workflowInfo,
[items[i]],
);

if (returnData[outputIndex] === undefined) {
returnData[outputIndex] = [];
}
for (const [outputIndex, outputData] of workflowResult.entries()) {
for (const item of outputData) {
item.pairedItem = { item: i };
}

if (returnData[outputIndex] === undefined) {
returnData[outputIndex] = [];
}

returnData[outputIndex].push(...outputData);
returnData[outputIndex].push(...outputData);
}
} else {
void this.executeWorkflow(workflowInfo, [items[i]]);
returnData = [items];
}
} catch (error) {
if (this.continueOnFail()) {
Expand All @@ -214,7 +243,18 @@ export class ExecuteWorkflow implements INodeType {
return returnData;
} else {
try {
const waitForSubWorkflow = this.getNodeParameter(
'options.waitForSubWorkflow',
0,
true,
) as boolean;
const workflowInfo = await getWorkflowInfo.call(this, source);

if (!waitForSubWorkflow) {
void this.executeWorkflow(workflowInfo, items);
return [items];
}

const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(
workflowInfo,
items,
Expand Down
Loading