mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
refactor(core): Rename EventsService
to WorkflowStatisticsService
(no-changelog) (#10107)
This commit is contained in:
parent
1c666e6e7c
commit
222a0862bd
|
@ -26,7 +26,7 @@ import type {
|
|||
IExecutionTrackProperties,
|
||||
} from '@/Interfaces';
|
||||
import { License } from '@/License';
|
||||
import { EventsService } from '@/services/events.service';
|
||||
import { WorkflowStatisticsService } from '@/services/workflow-statistics.service';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { Telemetry } from '@/telemetry';
|
||||
import type { Project } from '@db/entities/Project';
|
||||
|
@ -42,18 +42,18 @@ export class InternalHooks {
|
|||
private readonly nodeTypes: NodeTypes,
|
||||
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
|
||||
private readonly workflowRepository: WorkflowRepository,
|
||||
eventsService: EventsService,
|
||||
workflowStatisticsService: WorkflowStatisticsService,
|
||||
private readonly instanceSettings: InstanceSettings,
|
||||
private readonly license: License,
|
||||
private readonly projectRelationRepository: ProjectRelationRepository,
|
||||
private readonly sharedCredentialsRepository: SharedCredentialsRepository,
|
||||
private readonly _eventBus: MessageEventBus, // needed until we decouple telemetry
|
||||
) {
|
||||
eventsService.on(
|
||||
workflowStatisticsService.on(
|
||||
'telemetry.onFirstProductionWorkflowSuccess',
|
||||
async (metrics) => await this.onFirstProductionWorkflowSuccess(metrics),
|
||||
);
|
||||
eventsService.on(
|
||||
workflowStatisticsService.on(
|
||||
'telemetry.onFirstWorkflowDataLoad',
|
||||
async (metrics) => await this.onFirstWorkflowDataLoad(metrics),
|
||||
);
|
||||
|
|
|
@ -56,7 +56,7 @@ import * as WorkflowHelpers from '@/WorkflowHelpers';
|
|||
import { WorkflowRunner } from '@/WorkflowRunner';
|
||||
import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData';
|
||||
import { ActiveExecutions } from '@/ActiveExecutions';
|
||||
import { EventsService } from '@/services/events.service';
|
||||
import { WorkflowStatisticsService } from '@/services/workflow-statistics.service';
|
||||
import { OwnershipService } from './services/ownership.service';
|
||||
import { parseBody } from './middlewares';
|
||||
import { Logger } from './Logger';
|
||||
|
@ -360,7 +360,11 @@ export async function executeWebhook(
|
|||
NodeExecuteFunctions,
|
||||
executionMode,
|
||||
);
|
||||
Container.get(EventsService).emit('nodeFetchedData', workflow.id, workflowStartNode);
|
||||
Container.get(WorkflowStatisticsService).emit(
|
||||
'nodeFetchedData',
|
||||
workflow.id,
|
||||
workflowStartNode,
|
||||
);
|
||||
} catch (err) {
|
||||
// Send error response to webhook caller
|
||||
const errorMessage = 'Workflow Webhook Error: Workflow could not be started!';
|
||||
|
|
|
@ -54,7 +54,7 @@ import { findSubworkflowStart, isWorkflowIdValid } from '@/utils';
|
|||
import { PermissionChecker } from './UserManagement/PermissionChecker';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { ExecutionRepository } from '@db/repositories/execution.repository';
|
||||
import { EventsService } from '@/services/events.service';
|
||||
import { WorkflowStatisticsService } from '@/services/workflow-statistics.service';
|
||||
import { SecretsHelper } from './SecretsHelpers';
|
||||
import { OwnershipService } from './services/ownership.service';
|
||||
import {
|
||||
|
@ -393,7 +393,7 @@ export function hookFunctionsPreExecute(): IWorkflowExecuteHooks {
|
|||
*/
|
||||
function hookFunctionsSave(): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const eventsService = Container.get(EventsService);
|
||||
const workflowStatisticsService = Container.get(WorkflowStatisticsService);
|
||||
const eventRelay = Container.get(EventRelay);
|
||||
return {
|
||||
nodeExecuteBefore: [
|
||||
|
@ -524,13 +524,17 @@ function hookFunctionsSave(): IWorkflowExecuteHooks {
|
|||
);
|
||||
}
|
||||
} finally {
|
||||
eventsService.emit('workflowExecutionCompleted', this.workflowData, fullRunData);
|
||||
workflowStatisticsService.emit(
|
||||
'workflowExecutionCompleted',
|
||||
this.workflowData,
|
||||
fullRunData,
|
||||
);
|
||||
}
|
||||
},
|
||||
],
|
||||
nodeFetchedData: [
|
||||
async (workflowId: string, node: INode) => {
|
||||
eventsService.emit('nodeFetchedData', workflowId, node);
|
||||
workflowStatisticsService.emit('nodeFetchedData', workflowId, node);
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -545,7 +549,7 @@ function hookFunctionsSave(): IWorkflowExecuteHooks {
|
|||
function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||
const logger = Container.get(Logger);
|
||||
const internalHooks = Container.get(InternalHooks);
|
||||
const eventsService = Container.get(EventsService);
|
||||
const workflowStatisticsService = Container.get(WorkflowStatisticsService);
|
||||
const eventRelay = Container.get(EventRelay);
|
||||
return {
|
||||
nodeExecuteBefore: [
|
||||
|
@ -631,7 +635,11 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
|||
this.retryOf,
|
||||
);
|
||||
} finally {
|
||||
eventsService.emit('workflowExecutionCompleted', this.workflowData, fullRunData);
|
||||
workflowStatisticsService.emit(
|
||||
'workflowExecutionCompleted',
|
||||
this.workflowData,
|
||||
fullRunData,
|
||||
);
|
||||
}
|
||||
},
|
||||
async function (this: WorkflowHooks, runData: IRun): Promise<void> {
|
||||
|
@ -667,7 +675,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
|||
],
|
||||
nodeFetchedData: [
|
||||
async (workflowId: string, node: INode) => {
|
||||
eventsService.emit('nodeFetchedData', workflowId, node);
|
||||
workflowStatisticsService.emit('nodeFetchedData', workflowId, node);
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@ import { Logger } from '@/Logger';
|
|||
import { OwnershipService } from './ownership.service';
|
||||
|
||||
@Service()
|
||||
export class EventsService extends EventEmitter {
|
||||
export class WorkflowStatisticsService extends EventEmitter {
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly repository: WorkflowStatisticsRepository,
|
||||
|
@ -112,7 +112,7 @@ export class EventsService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
export declare interface EventsService {
|
||||
export declare interface WorkflowStatisticsService {
|
||||
on(
|
||||
event: 'nodeFetchedData',
|
||||
listener: (workflowId: string | undefined | null, node: INode) => void,
|
|
@ -14,13 +14,13 @@ import config from '@/config';
|
|||
import type { User } from '@db/entities/User';
|
||||
import type { WorkflowStatistics } from '@db/entities/WorkflowStatistics';
|
||||
import { WorkflowStatisticsRepository } from '@db/repositories/workflowStatistics.repository';
|
||||
import { EventsService } from '@/services/events.service';
|
||||
import { WorkflowStatisticsService } from '@/services/workflow-statistics.service';
|
||||
import { UserService } from '@/services/user.service';
|
||||
import { OwnershipService } from '@/services/ownership.service';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import type { Project } from '@/databases/entities/Project';
|
||||
|
||||
describe('EventsService', () => {
|
||||
describe('WorkflowStatisticsService', () => {
|
||||
const fakeUser = mock<User>({ id: 'abcde-fghij' });
|
||||
const fakeProject = mock<Project>({ id: '12345-67890', type: 'personal' });
|
||||
const ownershipService = mockInstance(OwnershipService);
|
||||
|
@ -44,7 +44,7 @@ describe('EventsService', () => {
|
|||
mocked(ownershipService.getProjectOwnerCached).mockResolvedValue(fakeUser);
|
||||
const updateSettingsMock = jest.spyOn(userService, 'updateSettings').mockImplementation();
|
||||
|
||||
const eventsService = new EventsService(
|
||||
const workflowStatisticsService = new WorkflowStatisticsService(
|
||||
mock(),
|
||||
new WorkflowStatisticsRepository(dataSource, globalConfig),
|
||||
ownershipService,
|
||||
|
@ -52,8 +52,11 @@ describe('EventsService', () => {
|
|||
|
||||
const onFirstProductionWorkflowSuccess = jest.fn();
|
||||
const onFirstWorkflowDataLoad = jest.fn();
|
||||
eventsService.on('telemetry.onFirstProductionWorkflowSuccess', onFirstProductionWorkflowSuccess);
|
||||
eventsService.on('telemetry.onFirstWorkflowDataLoad', onFirstWorkflowDataLoad);
|
||||
workflowStatisticsService.on(
|
||||
'telemetry.onFirstProductionWorkflowSuccess',
|
||||
onFirstProductionWorkflowSuccess,
|
||||
);
|
||||
workflowStatisticsService.on('telemetry.onFirstWorkflowDataLoad', onFirstWorkflowDataLoad);
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -91,7 +94,7 @@ describe('EventsService', () => {
|
|||
};
|
||||
mockDBCall();
|
||||
|
||||
await eventsService.workflowExecutionCompleted(workflow, runData);
|
||||
await workflowStatisticsService.workflowExecutionCompleted(workflow, runData);
|
||||
expect(updateSettingsMock).toHaveBeenCalledTimes(1);
|
||||
expect(onFirstProductionWorkflowSuccess).toBeCalledTimes(1);
|
||||
expect(onFirstProductionWorkflowSuccess).toHaveBeenNthCalledWith(1, {
|
||||
|
@ -119,7 +122,7 @@ describe('EventsService', () => {
|
|||
mode: 'internal' as WorkflowExecuteMode,
|
||||
startedAt: new Date(),
|
||||
};
|
||||
await eventsService.workflowExecutionCompleted(workflow, runData);
|
||||
await workflowStatisticsService.workflowExecutionCompleted(workflow, runData);
|
||||
expect(onFirstProductionWorkflowSuccess).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
|
@ -142,7 +145,7 @@ describe('EventsService', () => {
|
|||
startedAt: new Date(),
|
||||
};
|
||||
mockDBCall(2);
|
||||
await eventsService.workflowExecutionCompleted(workflow, runData);
|
||||
await workflowStatisticsService.workflowExecutionCompleted(workflow, runData);
|
||||
expect(onFirstProductionWorkflowSuccess).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
@ -159,7 +162,7 @@ describe('EventsService', () => {
|
|||
position: [0, 0] as [number, number],
|
||||
parameters: {},
|
||||
};
|
||||
await eventsService.nodeFetchedData(workflowId, node);
|
||||
await workflowStatisticsService.nodeFetchedData(workflowId, node);
|
||||
expect(onFirstWorkflowDataLoad).toBeCalledTimes(1);
|
||||
expect(onFirstWorkflowDataLoad).toHaveBeenNthCalledWith(1, {
|
||||
user_id: fakeUser.id,
|
||||
|
@ -187,7 +190,7 @@ describe('EventsService', () => {
|
|||
},
|
||||
},
|
||||
};
|
||||
await eventsService.nodeFetchedData(workflowId, node);
|
||||
await workflowStatisticsService.nodeFetchedData(workflowId, node);
|
||||
expect(onFirstWorkflowDataLoad).toBeCalledTimes(1);
|
||||
expect(onFirstWorkflowDataLoad).toHaveBeenNthCalledWith(1, {
|
||||
user_id: fakeUser.id,
|
||||
|
@ -212,7 +215,7 @@ describe('EventsService', () => {
|
|||
position: [0, 0] as [number, number],
|
||||
parameters: {},
|
||||
};
|
||||
await eventsService.nodeFetchedData(workflowId, node);
|
||||
await workflowStatisticsService.nodeFetchedData(workflowId, node);
|
||||
expect(onFirstWorkflowDataLoad).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue