UNPKG

n8n

Version:

n8n Workflow Automation Tool

79 lines 4.04 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiMainSetup = void 0; const typed_emitter_1 = require("../typed-emitter"); const backend_common_1 = require("@n8n/backend-common"); const config_1 = require("@n8n/config"); const constants_1 = require("@n8n/constants"); const decorators_1 = require("@n8n/decorators"); const di_1 = require("@n8n/di"); const n8n_core_1 = require("n8n-core"); const publisher_service_1 = require("../scaling/pubsub/publisher.service"); const redis_client_service_1 = require("../services/redis-client.service"); const multi_main_setup_legacy_1 = require("./multi-main-setup-legacy"); const multi_main_setup_v2_1 = require("./multi-main-setup-v2"); let MultiMainSetup = class MultiMainSetup extends typed_emitter_1.TypedEmitter { constructor(logger, instanceSettings, globalConfig, metadata, errorReporter, publisher, redisClientService) { super(); this.logger = logger; this.instanceSettings = instanceSettings; this.globalConfig = globalConfig; this.metadata = metadata; this.errorReporter = errorReporter; this.publisher = publisher; this.redisClientService = redisClientService; this.logger = this.logger.scoped(['scaling', 'multi-main-setup']); const emitFn = (event) => this.emit(event); if (this.globalConfig.multiMainSetup.newLeaderElection) { const { LeaderElectionClient } = require('../scaling/leader-election-client'); const client = di_1.Container.get(LeaderElectionClient); this.strategy = new multi_main_setup_v2_1.MultiMainSetupV2(this.logger, this.instanceSettings, this.errorReporter, client, emitFn); } else { this.strategy = new multi_main_setup_legacy_1.MultiMainSetupLegacy(this.logger, this.instanceSettings, this.publisher, this.redisClientService, this.globalConfig, this.errorReporter, emitFn); } } async init() { await this.strategy.init(); this.leaderCheckInterval = setInterval(async () => { await this.strategy.checkLeader(); }, this.globalConfig.multiMainSetup.interval * constants_1.Time.seconds.toMilliseconds); } async shutdown() { clearInterval(this.leaderCheckInterval); await this.strategy.shutdown(); } async fetchLeaderKey() { return await this.strategy.fetchLeaderKey(); } registerEventHandlers() { const handlers = this.metadata.getHandlers(); for (const { eventHandlerClass, methodName, eventName } of handlers) { const instance = di_1.Container.get(eventHandlerClass); this.on(eventName, async () => { return await instance[methodName].call(instance); }); } } }; exports.MultiMainSetup = MultiMainSetup; exports.MultiMainSetup = MultiMainSetup = __decorate([ (0, di_1.Service)(), __metadata("design:paramtypes", [backend_common_1.Logger, n8n_core_1.InstanceSettings, config_1.GlobalConfig, decorators_1.MultiMainMetadata, n8n_core_1.ErrorReporter, publisher_service_1.Publisher, redis_client_service_1.RedisClientService]) ], MultiMainSetup); //# sourceMappingURL=multi-main-setup.ee.js.map