chore: Convert ErrorReporting to a Service to use DI. Add some tests (no-changelog) (#11279)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-12-11 15:36:17 +01:00
committed by GitHub
parent 5300e0ac45
commit 73145b70b8
49 changed files with 443 additions and 386 deletions

View File

@@ -12,7 +12,14 @@ describe('JobProcessor', () => {
executionRepository.findSingleExecution.mockResolvedValue(
mock<IExecutionResponse>({ status: 'crashed' }),
);
const jobProcessor = new JobProcessor(mock(), executionRepository, mock(), mock(), mock());
const jobProcessor = new JobProcessor(
mock(),
mock(),
executionRepository,
mock(),
mock(),
mock(),
);
const result = await jobProcessor.processJob(mock<Job>());

View File

@@ -77,6 +77,7 @@ describe('ScalingService', () => {
scalingService = new ScalingService(
mockLogger(),
mock(),
mock(),
jobProcessor,
globalConfig,
mock(),

View File

@@ -1,12 +1,7 @@
import type { RunningJobSummary } from '@n8n/api-types';
import { InstanceSettings, WorkflowExecute } from 'n8n-core';
import { ErrorReporter, InstanceSettings, WorkflowExecute } from 'n8n-core';
import type { ExecutionStatus, IExecuteResponsePromiseData, IRun } from 'n8n-workflow';
import {
BINARY_ENCODING,
ApplicationError,
Workflow,
ErrorReporterProxy as ErrorReporter,
} from 'n8n-workflow';
import { BINARY_ENCODING, ApplicationError, Workflow } from 'n8n-workflow';
import type PCancelable from 'p-cancelable';
import { Service } from 'typedi';
@@ -35,6 +30,7 @@ export class JobProcessor {
constructor(
private readonly logger: Logger,
private readonly errorReporter: ErrorReporter,
private readonly executionRepository: ExecutionRepository,
private readonly workflowRepository: WorkflowRepository,
private readonly nodeTypes: NodeTypes,
@@ -155,7 +151,7 @@ export class JobProcessor {
workflowExecute = new WorkflowExecute(additionalData, execution.mode, execution.data);
workflowRun = workflowExecute.processRunExecutionData(workflow);
} else {
ErrorReporter.info(`Worker found execution ${executionId} without data`);
this.errorReporter.info(`Worker found execution ${executionId} without data`);
// Execute all nodes
// Can execute without webhook so go on
workflowExecute = new WorkflowExecute(additionalData, execution.mode);

View File

@@ -1,13 +1,6 @@
import { GlobalConfig } from '@n8n/config';
import { InstanceSettings } from 'n8n-core';
import {
ApplicationError,
BINARY_ENCODING,
sleep,
jsonStringify,
ErrorReporterProxy,
ensureError,
} from 'n8n-workflow';
import { ErrorReporter, InstanceSettings } from 'n8n-core';
import { ApplicationError, BINARY_ENCODING, sleep, jsonStringify, ensureError } from 'n8n-workflow';
import type { IExecuteResponsePromiseData } from 'n8n-workflow';
import { strict } from 'node:assert';
import Container, { Service } from 'typedi';
@@ -43,6 +36,7 @@ export class ScalingService {
constructor(
private readonly logger: Logger,
private readonly errorReporter: ErrorReporter,
private readonly activeExecutions: ActiveExecutions,
private readonly jobProcessor: JobProcessor,
private readonly globalConfig: GlobalConfig,
@@ -119,7 +113,7 @@ export class ScalingService {
await job.progress(msg);
ErrorReporterProxy.error(error, { executionId });
this.errorReporter.error(error, { executionId });
throw error;
}