mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
feat(Execute Workflow Node): Add 'Wait For Sub-Workflow Completion' option (#8389)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
parent
1b0ba2c028
commit
ff92fc7fef
|
@ -170,6 +170,23 @@ export class ExecuteWorkflow implements INodeType {
|
||||||
],
|
],
|
||||||
default: 'once',
|
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',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,25 +196,37 @@ export class ExecuteWorkflow implements INodeType {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
|
|
||||||
if (mode === 'each') {
|
if (mode === 'each') {
|
||||||
const returnData: INodeExecutionData[][] = [];
|
let returnData: INodeExecutionData[][] = [];
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
try {
|
try {
|
||||||
|
const waitForSubWorkflow = this.getNodeParameter(
|
||||||
|
'options.waitForSubWorkflow',
|
||||||
|
i,
|
||||||
|
true,
|
||||||
|
) as boolean;
|
||||||
const workflowInfo = await getWorkflowInfo.call(this, source, i);
|
const workflowInfo = await getWorkflowInfo.call(this, source, i);
|
||||||
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(workflowInfo, [
|
|
||||||
items[i],
|
|
||||||
]);
|
|
||||||
|
|
||||||
for (const [outputIndex, outputData] of workflowResult.entries()) {
|
if (waitForSubWorkflow) {
|
||||||
for (const item of outputData) {
|
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(
|
||||||
item.pairedItem = { item: i };
|
workflowInfo,
|
||||||
|
[items[i]],
|
||||||
|
);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (returnData[outputIndex] === undefined) {
|
void this.executeWorkflow(workflowInfo, [items[i]]);
|
||||||
returnData[outputIndex] = [];
|
returnData = [items];
|
||||||
}
|
|
||||||
|
|
||||||
returnData[outputIndex].push(...outputData);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.continueOnFail()) {
|
if (this.continueOnFail()) {
|
||||||
|
@ -214,7 +243,18 @@ export class ExecuteWorkflow implements INodeType {
|
||||||
return returnData;
|
return returnData;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
const waitForSubWorkflow = this.getNodeParameter(
|
||||||
|
'options.waitForSubWorkflow',
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
) as boolean;
|
||||||
const workflowInfo = await getWorkflowInfo.call(this, source);
|
const workflowInfo = await getWorkflowInfo.call(this, source);
|
||||||
|
|
||||||
|
if (!waitForSubWorkflow) {
|
||||||
|
void this.executeWorkflow(workflowInfo, items);
|
||||||
|
return [items];
|
||||||
|
}
|
||||||
|
|
||||||
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(
|
const workflowResult: INodeExecutionData[][] = await this.executeWorkflow(
|
||||||
workflowInfo,
|
workflowInfo,
|
||||||
items,
|
items,
|
||||||
|
|
Loading…
Reference in a new issue