mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(editor): Implement dirty nodes for partial executions (#11739)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
57d3269e40
commit
b8da4ff9ed
@@ -46,7 +46,13 @@ describe('findStartNodes', () => {
|
||||
const node = createNodeData({ name: 'Basic Node' });
|
||||
const graph = new DirectedGraph().addNode(node);
|
||||
|
||||
const startNodes = findStartNodes({ graph, trigger: node, destination: node });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger: node,
|
||||
destination: node,
|
||||
pinData: {},
|
||||
runData: {},
|
||||
});
|
||||
|
||||
expect(startNodes.size).toBe(1);
|
||||
expect(startNodes).toContainEqual(node);
|
||||
@@ -65,7 +71,13 @@ describe('findStartNodes', () => {
|
||||
|
||||
// if the trigger has no run data
|
||||
{
|
||||
const startNodes = findStartNodes({ graph, trigger, destination });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination,
|
||||
pinData: {},
|
||||
runData: {},
|
||||
});
|
||||
|
||||
expect(startNodes.size).toBe(1);
|
||||
expect(startNodes).toContainEqual(trigger);
|
||||
@@ -77,7 +89,13 @@ describe('findStartNodes', () => {
|
||||
[trigger.name]: [toITaskData([{ data: { value: 1 } }])],
|
||||
};
|
||||
|
||||
const startNodes = findStartNodes({ graph, trigger, destination, runData });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination,
|
||||
runData,
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
expect(startNodes.size).toBe(1);
|
||||
expect(startNodes).toContainEqual(destination);
|
||||
@@ -112,7 +130,13 @@ describe('findStartNodes', () => {
|
||||
};
|
||||
|
||||
// ACT
|
||||
const startNodes = findStartNodes({ graph, trigger, destination: node, runData });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination: node,
|
||||
runData,
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(startNodes.size).toBe(1);
|
||||
@@ -153,7 +177,13 @@ describe('findStartNodes', () => {
|
||||
|
||||
{
|
||||
// ACT
|
||||
const startNodes = findStartNodes({ graph, trigger, destination: node4 });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination: node4,
|
||||
pinData: {},
|
||||
runData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(startNodes.size).toBe(1);
|
||||
@@ -172,7 +202,13 @@ describe('findStartNodes', () => {
|
||||
};
|
||||
|
||||
// ACT
|
||||
const startNodes = findStartNodes({ graph, trigger, destination: node4, runData });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination: node4,
|
||||
runData,
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(startNodes.size).toBe(1);
|
||||
@@ -208,6 +244,7 @@ describe('findStartNodes', () => {
|
||||
runData: {
|
||||
[trigger.name]: [toITaskData([{ data: { value: 1 }, outputIndex: 0 }])],
|
||||
},
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
@@ -243,6 +280,7 @@ describe('findStartNodes', () => {
|
||||
runData: {
|
||||
[trigger.name]: [toITaskData([{ data: { value: 1 }, outputIndex: 1 }])],
|
||||
},
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
@@ -283,6 +321,7 @@ describe('findStartNodes', () => {
|
||||
]),
|
||||
],
|
||||
},
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
@@ -321,6 +360,7 @@ describe('findStartNodes', () => {
|
||||
[node1.name]: [toITaskData([{ data: { value: 1 }, outputIndex: 0 }])],
|
||||
[node2.name]: [toITaskData([{ data: { value: 1 }, outputIndex: 0 }])],
|
||||
},
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
@@ -357,6 +397,7 @@ describe('findStartNodes', () => {
|
||||
[trigger.name]: [toITaskData([{ data: { value: 1 } }])],
|
||||
[node1.name]: [toITaskData([{ data: { value: 1 }, outputIndex: 1 }])],
|
||||
},
|
||||
pinData: {},
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
@@ -389,7 +430,13 @@ describe('findStartNodes', () => {
|
||||
const pinData: IPinData = {};
|
||||
|
||||
// ACT
|
||||
const startNodes = findStartNodes({ graph, trigger, destination: node2, runData, pinData });
|
||||
const startNodes = findStartNodes({
|
||||
graph,
|
||||
trigger,
|
||||
destination: node2,
|
||||
runData,
|
||||
pinData,
|
||||
});
|
||||
|
||||
// ASSERT
|
||||
expect(startNodes.size).toBe(1);
|
||||
|
||||
@@ -135,14 +135,14 @@ export function findStartNodes(options: {
|
||||
graph: DirectedGraph;
|
||||
trigger: INode;
|
||||
destination: INode;
|
||||
runData?: IRunData;
|
||||
pinData?: IPinData;
|
||||
pinData: IPinData;
|
||||
runData: IRunData;
|
||||
}): Set<INode> {
|
||||
const graph = options.graph;
|
||||
const trigger = options.trigger;
|
||||
const destination = options.destination;
|
||||
const runData = options.runData ?? {};
|
||||
const pinData = options.pinData ?? {};
|
||||
const runData = { ...options.runData };
|
||||
const pinData = options.pinData;
|
||||
|
||||
const startNodes = findStartNodesRecursive(
|
||||
graph,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
||||
import * as assert from 'assert/strict';
|
||||
import { setMaxListeners } from 'events';
|
||||
import { omit } from 'lodash';
|
||||
import get from 'lodash/get';
|
||||
import type {
|
||||
ExecutionBaseError,
|
||||
@@ -319,8 +320,9 @@ export class WorkflowExecute {
|
||||
runPartialWorkflow2(
|
||||
workflow: Workflow,
|
||||
runData: IRunData,
|
||||
pinData: IPinData = {},
|
||||
dirtyNodeNames: string[] = [],
|
||||
destinationNodeName?: string,
|
||||
pinData?: IPinData,
|
||||
): PCancelable<IRun> {
|
||||
// TODO: Refactor the call-site to make `destinationNodeName` a required
|
||||
// after removing the old partial execution flow.
|
||||
@@ -349,7 +351,8 @@ export class WorkflowExecute {
|
||||
const filteredNodes = subgraph.getNodes();
|
||||
|
||||
// 3. Find the Start Nodes
|
||||
let startNodes = findStartNodes({ graph: subgraph, trigger, destination, runData });
|
||||
runData = omit(runData, dirtyNodeNames);
|
||||
let startNodes = findStartNodes({ graph: subgraph, trigger, destination, runData, pinData });
|
||||
|
||||
// 4. Detect Cycles
|
||||
// 5. Handle Cycles
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { IRun, WorkflowTestData } from 'n8n-workflow';
|
||||
import type { IPinData, IRun, IRunData, WorkflowTestData } from 'n8n-workflow';
|
||||
import {
|
||||
ApplicationError,
|
||||
createDeferredPromise,
|
||||
@@ -6,17 +6,20 @@ import {
|
||||
Workflow,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { DirectedGraph } from '@/PartialExecutionUtils';
|
||||
import { createNodeData, toITaskData } from '@/PartialExecutionUtils/__tests__/helpers';
|
||||
import { WorkflowExecute } from '@/WorkflowExecute';
|
||||
|
||||
import * as Helpers from './helpers';
|
||||
import { legacyWorkflowExecuteTests, v1WorkflowExecuteTests } from './helpers/constants';
|
||||
|
||||
const nodeTypes = Helpers.NodeTypes();
|
||||
|
||||
describe('WorkflowExecute', () => {
|
||||
describe('v0 execution order', () => {
|
||||
const tests: WorkflowTestData[] = legacyWorkflowExecuteTests;
|
||||
|
||||
const executionMode = 'manual';
|
||||
const nodeTypes = Helpers.NodeTypes();
|
||||
|
||||
for (const testData of tests) {
|
||||
test(testData.description, async () => {
|
||||
@@ -217,4 +220,49 @@ describe('WorkflowExecute', () => {
|
||||
expect(nodeExecutionOutput[0][0].json.data).toEqual(123);
|
||||
expect(nodeExecutionOutput.getHints()[0].message).toEqual('TEXT HINT');
|
||||
});
|
||||
|
||||
describe('runPartialWorkflow2', () => {
|
||||
// Dirty ►
|
||||
// ┌───────┐1 ┌─────┐1 ┌─────┐
|
||||
// │trigger├──────►node1├──────►node2│
|
||||
// └───────┘ └─────┘ └─────┘
|
||||
test("deletes dirty nodes' run data", async () => {
|
||||
// ARRANGE
|
||||
const waitPromise = createDeferredPromise<IRun>();
|
||||
const nodeExecutionOrder: string[] = [];
|
||||
const additionalData = Helpers.WorkflowExecuteAdditionalData(waitPromise, nodeExecutionOrder);
|
||||
const workflowExecute = new WorkflowExecute(additionalData, 'manual');
|
||||
|
||||
const trigger = createNodeData({ name: 'trigger', type: 'n8n-nodes-base.manualTrigger' });
|
||||
const node1 = createNodeData({ name: 'node1' });
|
||||
const node2 = createNodeData({ name: 'node2' });
|
||||
const workflow = new DirectedGraph()
|
||||
.addNodes(trigger, node1, node2)
|
||||
.addConnections({ from: trigger, to: node1 }, { from: node1, to: node2 })
|
||||
.toWorkflow({ name: '', active: false, nodeTypes });
|
||||
const pinData: IPinData = {};
|
||||
const runData: IRunData = {
|
||||
[trigger.name]: [toITaskData([{ data: { name: trigger.name } }])],
|
||||
[node1.name]: [toITaskData([{ data: { name: node1.name } }])],
|
||||
[node2.name]: [toITaskData([{ data: { name: node2.name } }])],
|
||||
};
|
||||
const dirtyNodeNames = [node1.name];
|
||||
|
||||
jest.spyOn(workflowExecute, 'processRunExecutionData').mockImplementationOnce(jest.fn());
|
||||
|
||||
// ACT
|
||||
await workflowExecute.runPartialWorkflow2(
|
||||
workflow,
|
||||
runData,
|
||||
pinData,
|
||||
dirtyNodeNames,
|
||||
'node2',
|
||||
);
|
||||
|
||||
// ASSERT
|
||||
const fullRunData = workflowExecute.getFullRunData(new Date());
|
||||
expect(fullRunData.data.resultData.runData).toHaveProperty(trigger.name);
|
||||
expect(fullRunData.data.resultData.runData).not.toHaveProperty(node1.name);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
|
||||
import { If } from '../../../nodes-base/dist/nodes/If/If.node';
|
||||
import { ManualTrigger } from '../../../nodes-base/dist/nodes/ManualTrigger/ManualTrigger.node';
|
||||
import { Merge } from '../../../nodes-base/dist/nodes/Merge/Merge.node';
|
||||
import { NoOp } from '../../../nodes-base/dist/nodes/NoOp/NoOp.node';
|
||||
import { Set } from '../../../nodes-base/dist/nodes/Set/Set.node';
|
||||
@@ -33,6 +34,10 @@ export const predefinedNodesTypes: INodeTypeData = {
|
||||
type: new Start(),
|
||||
sourcePath: '',
|
||||
},
|
||||
'n8n-nodes-base.manualTrigger': {
|
||||
type: new ManualTrigger(),
|
||||
sourcePath: '',
|
||||
},
|
||||
'n8n-nodes-base.versionTest': {
|
||||
sourcePath: '',
|
||||
type: {
|
||||
|
||||
Reference in New Issue
Block a user