mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-23 10:30:42 +02:00
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { BaseN8nModule } from '@n8n/decorators';
|
|
import { N8nModule, OnLeaderStepdown, OnLeaderTakeover } from '@n8n/decorators';
|
|
import type { ExecutionLifecycleHooks } from 'n8n-core';
|
|
import { InstanceSettings, Logger } from 'n8n-core';
|
|
|
|
import { InsightsService } from './insights.service';
|
|
|
|
import './insights.controller';
|
|
|
|
@N8nModule()
|
|
export class InsightsModule implements BaseN8nModule {
|
|
constructor(
|
|
private readonly logger: Logger,
|
|
private readonly insightsService: InsightsService,
|
|
private readonly instanceSettings: InstanceSettings,
|
|
) {
|
|
this.logger = this.logger.scoped('insights');
|
|
}
|
|
|
|
initialize() {
|
|
// We want to initialize the insights background process (schedulers) for the main leader instance
|
|
// to have only one main instance saving the insights data
|
|
if (this.instanceSettings.isLeader) {
|
|
this.insightsService.startBackgroundProcess();
|
|
}
|
|
}
|
|
|
|
registerLifecycleHooks(hooks: ExecutionLifecycleHooks) {
|
|
const insightsService = this.insightsService;
|
|
|
|
hooks.addHandler('workflowExecuteAfter', async function (fullRunData) {
|
|
await insightsService.workflowExecuteAfterHandler(this, fullRunData);
|
|
});
|
|
}
|
|
|
|
@OnLeaderTakeover()
|
|
startBackgroundProcess() {
|
|
this.insightsService.startBackgroundProcess();
|
|
}
|
|
|
|
@OnLeaderStepdown()
|
|
stopBackgroundProcess() {
|
|
this.insightsService.stopBackgroundProcess();
|
|
}
|
|
}
|