chore(core): Add instanceType condition to load insights module only for main aand webhook (#22052)

This commit is contained in:
Guillaume Jacquart 2025-11-20 11:11:56 +01:00 committed by GitHub
parent 34039b370b
commit db16933c5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import { mock } from 'jest-mock-extended';
import { InstanceSettings } from 'n8n-core';
import { InsightsModule } from '../insights.module';
import { InsightsService } from '../insights.service';
describe('InsightsModule', () => {
let insightsModule: InsightsModule;
@ -23,11 +24,23 @@ describe('InsightsModule', () => {
beforeEach(async () => {
jest.clearAllMocks();
await testDb.truncate(['Project']);
insightsModule = Container.get(InsightsModule);
mockInstanceSettings = mock<InstanceSettings>();
Container.set(InstanceSettings, mockInstanceSettings);
Container.set(Logger, mockLogger());
Container.set(LicenseState, mock<LicenseState>());
Container.set(
InsightsService,
new InsightsService(
mock(),
mock(),
mock(),
Container.get(LicenseState),
mockInstanceSettings,
Container.get(Logger),
),
);
insightsModule = Container.get(InsightsModule);
await createTeamProject();
});

View File

@ -1,17 +1,14 @@
import type { ModuleInterface } from '@n8n/decorators';
import { BackendModule, OnShutdown } from '@n8n/decorators';
import { Container } from '@n8n/di';
import { InstanceSettings } from 'n8n-core';
@BackendModule({ name: 'insights' })
/**
* Only main- and webhook-type instances collect insights because
* only they are informed of finished workflow executions.
*/
@BackendModule({ name: 'insights', instanceTypes: ['main', 'webhook'] })
export class InsightsModule implements ModuleInterface {
async init() {
/**
* Only main- and webhook-type instances collect insights because
* only they are informed of finished workflow executions.
*/
if (Container.get(InstanceSettings).instanceType === 'worker') return;
await import('./insights.controller');
const { InsightsService } = await import('./insights.service');