Skip to content

Commit

Permalink
Fix dependency cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Jun 12, 2024
1 parent 09e14b3 commit c0ff93f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Logger>();
const executionRepository = mock<ExecutionRepository>();
const internalHooks = mock<InternalHooks>();
const telemetry = mock<Telemetry>();

afterEach(() => {
config.set('executions.concurrency.productionLimit', -1);
Expand All @@ -31,7 +31,7 @@ describe('ConcurrencyControlService', () => {
/**
* Act
*/
const service = new ConcurrencyControlService(logger, executionRepository, internalHooks);
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);

/**
* Assert
Expand All @@ -52,7 +52,7 @@ describe('ConcurrencyControlService', () => {
/**
* Act
*/
new ConcurrencyControlService(logger, executionRepository, internalHooks);
new ConcurrencyControlService(logger, executionRepository, telemetry);
} catch (error) {
/**
* Assert
Expand All @@ -70,7 +70,7 @@ describe('ConcurrencyControlService', () => {
/**
* Act
*/
const service = new ConcurrencyControlService(logger, executionRepository, internalHooks);
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);

/**
* Assert
Expand All @@ -88,7 +88,7 @@ describe('ConcurrencyControlService', () => {
/**
* Act
*/
const service = new ConcurrencyControlService(logger, executionRepository, internalHooks);
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);

/**
* Act
Expand All @@ -107,7 +107,7 @@ describe('ConcurrencyControlService', () => {
/**
* Act
*/
const service = new ConcurrencyControlService(logger, executionRepository, internalHooks);
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);

/**
* Assert
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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')
Expand Down Expand Up @@ -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');

/**
Expand All @@ -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');

/**
Expand All @@ -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');

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/concurrency/concurrency-control.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');

Expand Down Expand Up @@ -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 });
}
},
);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c0ff93f

Please sign in to comment.