diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index 09ac2d2412..454f4be002 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -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), ); diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index 6f2d01cdda..95e8825e1a 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -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!'; diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 62bcc5a67f..99a3ff731a 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -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 { @@ -667,7 +675,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks { ], nodeFetchedData: [ async (workflowId: string, node: INode) => { - eventsService.emit('nodeFetchedData', workflowId, node); + workflowStatisticsService.emit('nodeFetchedData', workflowId, node); }, ], }; diff --git a/packages/cli/src/services/events.service.ts b/packages/cli/src/services/workflow-statistics.service.ts similarity index 97% rename from packages/cli/src/services/events.service.ts rename to packages/cli/src/services/workflow-statistics.service.ts index 7f5ad4c121..516732add8 100644 --- a/packages/cli/src/services/events.service.ts +++ b/packages/cli/src/services/workflow-statistics.service.ts @@ -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, diff --git a/packages/cli/test/unit/services/events.service.test.ts b/packages/cli/test/unit/services/workflow-statistics.service.test.ts similarity index 88% rename from packages/cli/test/unit/services/events.service.test.ts rename to packages/cli/test/unit/services/workflow-statistics.service.test.ts index 0fbab36623..da1338f8eb 100644 --- a/packages/cli/test/unit/services/events.service.test.ts +++ b/packages/cli/test/unit/services/workflow-statistics.service.test.ts @@ -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({ id: 'abcde-fghij' }); const fakeProject = mock({ 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); }); });