mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Use an IoC container to manage singleton classes [Part-1] (no-changelog) (#5509)
* add typedi * convert ActiveWorkflowRunner into an injectable service * convert ExternalHooks into an injectable service * convert InternalHooks into an injectable service * convert LoadNodesAndCredentials into an injectable service * convert NodeTypes and CredentialTypes into an injectable service * convert ActiveExecutions into an injectable service * convert WaitTracker into an injectable service * convert Push into an injectable service * convert ActiveWebhooks and TestWebhooks into an injectable services * handle circular references, and log errors when a circular dependency is found
This commit is contained in:
committed by
GitHub
parent
aca94bb995
commit
52f740b9e8
@@ -7,6 +7,8 @@
|
||||
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
import 'source-map-support/register';
|
||||
import 'reflect-metadata';
|
||||
import { Container } from 'typedi';
|
||||
import type { IProcessMessage } from 'n8n-core';
|
||||
import { BinaryDataManager, UserSettings, WorkflowExecute } from 'n8n-core';
|
||||
|
||||
@@ -49,11 +51,11 @@ import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData'
|
||||
import { getLogger } from '@/Logger';
|
||||
|
||||
import config from '@/config';
|
||||
import { InternalHooksManager } from '@/InternalHooksManager';
|
||||
import { generateFailedExecutionFromError } from '@/WorkflowHelpers';
|
||||
import { initErrorHandling } from '@/ErrorReporting';
|
||||
import { PermissionChecker } from '@/UserManagement/PermissionChecker';
|
||||
import { getLicense } from './License';
|
||||
import { InternalHooks } from './InternalHooks';
|
||||
import { PostHogClient } from './posthog';
|
||||
|
||||
class WorkflowRunnerProcess {
|
||||
@@ -104,23 +106,20 @@ class WorkflowRunnerProcess {
|
||||
|
||||
const userSettings = await UserSettings.prepareUserSettings();
|
||||
|
||||
const loadNodesAndCredentials = LoadNodesAndCredentials();
|
||||
const loadNodesAndCredentials = Container.get(LoadNodesAndCredentials);
|
||||
await loadNodesAndCredentials.init();
|
||||
|
||||
const nodeTypes = NodeTypes(loadNodesAndCredentials);
|
||||
const credentialTypes = CredentialTypes(loadNodesAndCredentials);
|
||||
const nodeTypes = Container.get(NodeTypes);
|
||||
const credentialTypes = Container.get(CredentialTypes);
|
||||
CredentialsOverwrites(credentialTypes);
|
||||
|
||||
// Load all external hooks
|
||||
const externalHooks = ExternalHooks();
|
||||
const externalHooks = Container.get(ExternalHooks);
|
||||
await externalHooks.init();
|
||||
|
||||
const instanceId = userSettings.instanceId ?? '';
|
||||
|
||||
const postHog = new PostHogClient();
|
||||
await postHog.init(instanceId);
|
||||
|
||||
await InternalHooksManager.init(instanceId, nodeTypes, postHog);
|
||||
await Container.get(PostHogClient).init(instanceId);
|
||||
await Container.get(InternalHooks).init(instanceId);
|
||||
|
||||
const binaryDataConfig = config.getEnv('binaryDataManager');
|
||||
await BinaryDataManager.init(binaryDataConfig);
|
||||
@@ -234,7 +233,7 @@ class WorkflowRunnerProcess {
|
||||
};
|
||||
});
|
||||
|
||||
void InternalHooksManager.getInstance().onWorkflowBeforeExecute(executionId || '', runData);
|
||||
void Container.get(InternalHooks).onWorkflowBeforeExecute(executionId || '', runData);
|
||||
|
||||
let result: IRun;
|
||||
try {
|
||||
@@ -255,7 +254,7 @@ class WorkflowRunnerProcess {
|
||||
const { workflow } = executeWorkflowFunctionOutput;
|
||||
result = await workflowExecute.processRunExecutionData(workflow);
|
||||
await externalHooks.run('workflow.postExecute', [result, workflowData, executionId]);
|
||||
void InternalHooksManager.getInstance().onWorkflowPostExecute(
|
||||
void Container.get(InternalHooks).onWorkflowPostExecute(
|
||||
executionId,
|
||||
workflowData,
|
||||
result,
|
||||
@@ -513,6 +512,8 @@ process.on('message', async (message: IProcessMessage) => {
|
||||
workflowRunner.executionIdCallback(message.data.executionId);
|
||||
}
|
||||
} catch (error) {
|
||||
workflowRunner.logger.error(error.message);
|
||||
|
||||
// Catch all uncaught errors and forward them to parent process
|
||||
const executionError = {
|
||||
...error,
|
||||
|
||||
Reference in New Issue
Block a user