mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(core): Load insights module on webhook instance to save insights on webhook workflows (#15433)
This commit is contained in:
committed by
GitHub
parent
d9fdef3bf9
commit
bf5551d711
@@ -1,22 +1,25 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
import type { InstanceSettings, InstanceType } from 'n8n-core';
|
||||
|
||||
import type { ModulePreInitContext } from '@/modules/modules.config';
|
||||
|
||||
import { shouldLoadModule } from '../insights.pre-init';
|
||||
|
||||
describe('InsightsModulePreInit', () => {
|
||||
it('should return false if instance type is not "main"', () => {
|
||||
it('should return false if instance type is worker', () => {
|
||||
const ctx: ModulePreInitContext = {
|
||||
instance: mock<InstanceSettings>({ instanceType: 'worker' }),
|
||||
};
|
||||
expect(shouldLoadModule(ctx)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if instance type is "main"', () => {
|
||||
const ctx: ModulePreInitContext = {
|
||||
instance: mock<InstanceSettings>({ instanceType: 'main' }),
|
||||
};
|
||||
expect(shouldLoadModule(ctx)).toBe(true);
|
||||
});
|
||||
it.each<InstanceType>(['main', 'webhook'])(
|
||||
'should return true if instance type is "%s"',
|
||||
(instanceType) => {
|
||||
const ctx: ModulePreInitContext = {
|
||||
instance: mock<InstanceSettings>({ instanceType }),
|
||||
};
|
||||
expect(shouldLoadModule(ctx)).toBe(true);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ModulePreInitContext } from '../modules.config';
|
||||
|
||||
export const shouldLoadModule = (ctx: ModulePreInitContext) =>
|
||||
// Only main instance(s) should collect insights
|
||||
// Because main instances are informed of all finished workflow executions, whatever the mode
|
||||
ctx.instance.instanceType === 'main';
|
||||
// Only main and webhook instance(s) should collect insights
|
||||
// Because main and webhooks instances are the ones informed of all finished workflow executions, whatever the mode
|
||||
ctx.instance.instanceType === 'main' || ctx.instance.instanceType === 'webhook';
|
||||
|
||||
Reference in New Issue
Block a user