Skip to content

Commit 0c2e666

Browse files
authored
refactor(core): Initial setup for execution data management (n8n-io#24452)
1 parent 5dd15e3 commit 0c2e666

6 files changed

Lines changed: 31 additions & 12 deletions

File tree

packages/cli/src/executions/__tests__/execution-data.service.test.ts renamed to packages/cli/src/executions/__tests__/failed-run-factory.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { mock } from 'jest-mock-extended';
22
import { NodeOperationError } from 'n8n-workflow';
33
import type { INode, WorkflowExecuteMode } from 'n8n-workflow';
44

5-
import { ExecutionDataService } from '../execution-data.service';
5+
import { FailedRunFactory } from '../failed-run-factory';
66

7-
describe('ExecutionDataService', () => {
8-
const service = new ExecutionDataService();
7+
describe('FailedRunFactory', () => {
8+
const service = new FailedRunFactory();
99

1010
describe('generateFailedExecutionFromError', () => {
1111
const mode: WorkflowExecuteMode = 'manual';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { IWorkflowBase } from 'n8n-workflow';
2+
3+
type ExecutionRef = {
4+
workflowId: string;
5+
executionId: string;
6+
};
7+
8+
type ExecutionDataPayload = {
9+
data: string;
10+
workflowData: IWorkflowBase;
11+
workflowVersionId: string | null;
12+
};
13+
14+
export interface ExecutionDataManager {
15+
init?(): Promise<void>;
16+
write(ref: ExecutionRef, payload: ExecutionDataPayload): Promise<void>;
17+
read(ref: ExecutionRef): Promise<ExecutionDataPayload>;
18+
delete(ref: ExecutionRef | ExecutionRef[]): Promise<void>;
19+
}

packages/cli/src/executions/execution-data.service.ts renamed to packages/cli/src/executions/failed-run-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'n8n-workflow';
99

1010
@Service()
11-
export class ExecutionDataService {
11+
export class FailedRunFactory {
1212
generateFailedExecutionFromError(
1313
mode: WorkflowExecuteMode,
1414
error: ExecutionError,

packages/cli/src/workflow-execute-additional-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { CredentialsHelper } from '@/credentials-helper';
3737
import { EventService } from '@/events/event.service';
3838
import type { AiEventMap, AiEventPayload } from '@/events/maps/ai.event-map';
3939
import { getLifecycleHooksForSubExecutions } from '@/execution-lifecycle/execution-lifecycle-hooks';
40-
import { ExecutionDataService } from '@/executions/execution-data.service';
40+
import { FailedRunFactory } from '@/executions/failed-run-factory';
4141
import { isManualOrChatExecution } from '@/executions/execution.utils';
4242
import {
4343
CredentialsPermissionChecker,
@@ -342,7 +342,7 @@ async function startExecution(
342342
data = await execution;
343343
} catch (error) {
344344
const executionError = error as ExecutionError;
345-
const fullRunData = Container.get(ExecutionDataService).generateFailedExecutionFromError(
345+
const fullRunData = Container.get(FailedRunFactory).generateFailedExecutionFromError(
346346
runData.executionMode,
347347
executionError,
348348
'node' in executionError ? executionError.node : undefined,

packages/cli/src/workflow-runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
getLifecycleHooksForScalingWorker,
3636
getLifecycleHooksForScalingMain,
3737
} from '@/execution-lifecycle/execution-lifecycle-hooks';
38-
import { ExecutionDataService } from '@/executions/execution-data.service';
38+
import { FailedRunFactory } from '@/executions/failed-run-factory';
3939
import { CredentialsPermissionChecker } from '@/executions/pre-execution-checks';
4040
import { ManualExecutionService } from '@/manual-execution.service';
4141
import { NodeTypes } from '@/node-types';
@@ -60,7 +60,7 @@ export class WorkflowRunner {
6060
private readonly credentialsPermissionChecker: CredentialsPermissionChecker,
6161
private readonly instanceSettings: InstanceSettings,
6262
private readonly manualExecutionService: ManualExecutionService,
63-
private readonly executionDataService: ExecutionDataService,
63+
private readonly failedRunFactory: FailedRunFactory,
6464
private readonly eventService: EventService,
6565
private readonly executionsConfig: ExecutionsConfig,
6666
) {}
@@ -147,7 +147,7 @@ export class WorkflowRunner {
147147
await this.credentialsPermissionChecker.check(workflowId, nodes);
148148
} catch (error) {
149149
// Create a failed execution with the data for the node, save it and abort execution
150-
const runData = this.executionDataService.generateFailedExecutionFromError(
150+
const runData = this.failedRunFactory.generateFailedExecutionFromError(
151151
data.executionMode,
152152
error,
153153
error.node,

packages/cli/src/workflows/workflow-execution.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from 'n8n-workflow';
2727

2828
import { EventService } from '@/events/event.service';
29-
import { ExecutionDataService } from '@/executions/execution-data.service';
29+
import { FailedRunFactory } from '@/executions/failed-run-factory';
3030
import { SubworkflowPolicyChecker } from '@/executions/pre-execution-checks';
3131
import type { IWorkflowErrorData } from '@/interfaces';
3232
import { NodeTypes } from '@/node-types';
@@ -47,7 +47,7 @@ export class WorkflowExecutionService {
4747
private readonly workflowRunner: WorkflowRunner,
4848
private readonly globalConfig: GlobalConfig,
4949
private readonly subworkflowPolicyChecker: SubworkflowPolicyChecker,
50-
private readonly executionDataService: ExecutionDataService,
50+
private readonly failedRunFactory: FailedRunFactory,
5151
private readonly eventService: EventService,
5252
) {}
5353

@@ -342,7 +342,7 @@ export class WorkflowExecutionService {
342342
);
343343

344344
// Create a fake execution and save it to DB.
345-
const fakeExecution = this.executionDataService.generateFailedExecutionFromError(
345+
const fakeExecution = this.failedRunFactory.generateFailedExecutionFromError(
346346
'error',
347347
errorWorkflowPermissionError,
348348
initialNode,

0 commit comments

Comments
 (0)