mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-27 12:11:43 +02:00
refactor(core): Decouple leadership-change handlers using decorators (#15009)
This commit is contained in:
@@ -18,6 +18,7 @@ import type { TypeUnit } from '@/modules/insights/database/entities/insights-sha
|
||||
import { InsightsMetadataRepository } from '@/modules/insights/database/repositories/insights-metadata.repository';
|
||||
import { InsightsRawRepository } from '@/modules/insights/database/repositories/insights-raw.repository';
|
||||
import type { IWorkflowDb } from '@/types-db';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
import { createTeamProject } from '@test-integration/db/projects';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
import * as testDb from '@test-integration/test-db';
|
||||
@@ -284,7 +285,7 @@ describe('workflowExecuteAfterHandler - cacheMetadata', () => {
|
||||
insightsCollectionService = new InsightsCollectionService(
|
||||
sharedWorkflowRepositoryMock,
|
||||
Container.get(InsightsConfig),
|
||||
mock<Logger>(),
|
||||
mockLogger(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { InsightsDateRange } from '@n8n/api-types';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DateTime } from 'luxon';
|
||||
import type { Logger } from 'n8n-core';
|
||||
|
||||
import type { Project } from '@/databases/entities/project';
|
||||
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
|
||||
@@ -502,7 +501,6 @@ describe('getAvailableDateRanges', () => {
|
||||
mock<InsightsCompactionService>(),
|
||||
mock<InsightsCollectionService>(),
|
||||
licenseMock,
|
||||
mock<Logger>(),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -603,7 +601,6 @@ describe('getMaxAgeInDaysAndGranularity', () => {
|
||||
mock<InsightsCompactionService>(),
|
||||
mock<InsightsCollectionService>(),
|
||||
licenseMock,
|
||||
mock<Logger>(),
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -77,12 +77,14 @@ export class InsightsCollectionService {
|
||||
async () => await this.flushEvents(),
|
||||
this.insightsConfig.flushIntervalSeconds * 1000,
|
||||
);
|
||||
this.logger.debug('Started flushing timer');
|
||||
}
|
||||
|
||||
stopFlushingTimer() {
|
||||
if (this.flushInsightsRawBufferTimer !== undefined) {
|
||||
clearTimeout(this.flushInsightsRawBufferTimer);
|
||||
this.flushInsightsRawBufferTimer = undefined;
|
||||
this.logger.debug('Stopped flushing timer');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Service } from '@n8n/di';
|
||||
import { Logger } from 'n8n-core';
|
||||
|
||||
import { InsightsByPeriodRepository } from './database/repositories/insights-by-period.repository';
|
||||
import { InsightsRawRepository } from './database/repositories/insights-raw.repository';
|
||||
@@ -16,7 +17,10 @@ export class InsightsCompactionService {
|
||||
private readonly insightsByPeriodRepository: InsightsByPeriodRepository,
|
||||
private readonly insightsRawRepository: InsightsRawRepository,
|
||||
private readonly insightsConfig: InsightsConfig,
|
||||
) {}
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
this.logger = this.logger.scoped('insights');
|
||||
}
|
||||
|
||||
startCompactionTimer() {
|
||||
this.stopCompactionTimer();
|
||||
@@ -24,12 +28,14 @@ export class InsightsCompactionService {
|
||||
async () => await this.compactInsights(),
|
||||
this.insightsConfig.compactionIntervalMinutes * 60 * 1000,
|
||||
);
|
||||
this.logger.debug('Started compaction timer');
|
||||
}
|
||||
|
||||
stopCompactionTimer() {
|
||||
if (this.compactInsightsTimer !== undefined) {
|
||||
clearInterval(this.compactInsightsTimer);
|
||||
this.compactInsightsTimer = undefined;
|
||||
this.logger.debug('Stopped compaction timer');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from '@n8n/api-types';
|
||||
import { OnShutdown } from '@n8n/decorators';
|
||||
import { Service } from '@n8n/di';
|
||||
import { Logger } from 'n8n-core';
|
||||
import { UserError } from 'n8n-workflow';
|
||||
|
||||
import { License } from '@/license';
|
||||
@@ -33,19 +32,16 @@ export class InsightsService {
|
||||
private readonly compactionService: InsightsCompactionService,
|
||||
private readonly collectionService: InsightsCollectionService,
|
||||
private readonly license: License,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
startBackgroundProcess() {
|
||||
this.compactionService.startCompactionTimer();
|
||||
this.collectionService.startFlushingTimer();
|
||||
this.logger.debug('Started compaction and flushing schedulers');
|
||||
}
|
||||
|
||||
stopBackgroundProcess() {
|
||||
this.compactionService.stopCompactionTimer();
|
||||
this.collectionService.stopFlushingTimer();
|
||||
this.logger.debug('Stopped compaction and flushing schedulers');
|
||||
}
|
||||
|
||||
@OnShutdown()
|
||||
|
||||
Reference in New Issue
Block a user