From c0ff93fa187f16aecad98aac144973c3a731f884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 12 Jun 2024 10:53:42 +0200 Subject: [PATCH] Fix dependency cycle --- .../concurrency-control.service.test.ts | 34 +++++++++---------- .../concurrency-control.service.ts | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/cli/src/concurrency/__tests__/concurrency-control.service.test.ts b/packages/cli/src/concurrency/__tests__/concurrency-control.service.test.ts index 90361086fc72a..1c80d8de60471 100644 --- a/packages/cli/src/concurrency/__tests__/concurrency-control.service.test.ts +++ b/packages/cli/src/concurrency/__tests__/concurrency-control.service.test.ts @@ -7,12 +7,12 @@ import { ConcurrencyQueue } from '../concurrency-queue'; import type { WorkflowExecuteMode as ExecutionMode } from 'n8n-workflow'; import type { ExecutionRepository } from '@/databases/repositories/execution.repository'; import type { IExecutingWorkflowData } from '@/Interfaces'; -import type { InternalHooks } from '@/InternalHooks'; +import type { Telemetry } from '@/telemetry'; describe('ConcurrencyControlService', () => { const logger = mock(); const executionRepository = mock(); - const internalHooks = mock(); + const telemetry = mock(); afterEach(() => { config.set('executions.concurrency.productionLimit', -1); @@ -31,7 +31,7 @@ describe('ConcurrencyControlService', () => { /** * Act */ - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); /** * Assert @@ -52,7 +52,7 @@ describe('ConcurrencyControlService', () => { /** * Act */ - new ConcurrencyControlService(logger, executionRepository, internalHooks); + new ConcurrencyControlService(logger, executionRepository, telemetry); } catch (error) { /** * Assert @@ -70,7 +70,7 @@ describe('ConcurrencyControlService', () => { /** * Act */ - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); /** * Assert @@ -88,7 +88,7 @@ describe('ConcurrencyControlService', () => { /** * Act */ - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); /** * Act @@ -107,7 +107,7 @@ describe('ConcurrencyControlService', () => { /** * Act */ - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); /** * Assert @@ -131,7 +131,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const enqueueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'enqueue'); /** @@ -152,7 +152,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const enqueueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'enqueue'); /** @@ -176,7 +176,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const dequeueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'dequeue'); /** @@ -197,7 +197,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const dequeueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'dequeue'); /** @@ -221,7 +221,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const removeSpy = jest.spyOn(ConcurrencyQueue.prototype, 'remove'); /** @@ -244,7 +244,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const removeSpy = jest.spyOn(ConcurrencyQueue.prototype, 'remove'); /** @@ -267,7 +267,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', 2); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); jest .spyOn(ConcurrencyQueue.prototype, 'getAll') @@ -306,7 +306,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', -1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const enqueueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'enqueue'); /** @@ -329,7 +329,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', -1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const dequeueSpy = jest.spyOn(ConcurrencyQueue.prototype, 'dequeue'); /** @@ -351,7 +351,7 @@ describe('ConcurrencyControlService', () => { */ config.set('executions.concurrency.productionLimit', -1); - const service = new ConcurrencyControlService(logger, executionRepository, internalHooks); + const service = new ConcurrencyControlService(logger, executionRepository, telemetry); const removeSpy = jest.spyOn(ConcurrencyQueue.prototype, 'remove'); /** diff --git a/packages/cli/src/concurrency/concurrency-control.service.ts b/packages/cli/src/concurrency/concurrency-control.service.ts index 152517ec0800a..21429c00ed815 100644 --- a/packages/cli/src/concurrency/concurrency-control.service.ts +++ b/packages/cli/src/concurrency/concurrency-control.service.ts @@ -7,7 +7,7 @@ import { InvalidConcurrencyLimitError } from '@/errors/invalid-concurrency-limit import { ExecutionRepository } from '@/databases/repositories/execution.repository'; import type { WorkflowExecuteMode as ExecutionMode } from 'n8n-workflow'; import type { IExecutingWorkflowData } from '@/Interfaces'; -import { InternalHooks } from '@/InternalHooks'; +import { Telemetry } from '@/telemetry'; @Service() export class ConcurrencyControlService { @@ -22,7 +22,7 @@ export class ConcurrencyControlService { constructor( private readonly logger: Logger, private readonly executionRepository: ExecutionRepository, - private readonly internalHooks: InternalHooks, + private readonly telemetry: Telemetry, ) { this.productionLimit = config.getEnv('executions.concurrency.productionLimit'); @@ -55,7 +55,7 @@ export class ConcurrencyControlService { * Temporary until base data for cloud plans is collected. */ if (this.shouldReport(capacity)) { - await this.internalHooks.onConcurrencyLimitHit({ threshold: capacity }); + await this.telemetry.track('User hit concurrency limit', { threshold: capacity }); } }, ); @@ -151,7 +151,7 @@ export class ConcurrencyControlService { } private log(message: string, meta?: object) { - this.logger.info(['[Concurrency Control]', message].join(' '), meta); + this.logger.debug(['[Concurrency Control]', message].join(' '), meta); } private shouldReport(capacity: number) {