n8n
Version:
n8n Workflow Automation Tool
122 lines • 4.88 kB
JavaScript
"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);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrchestrationService = void 0;
const typedi_1 = require("typedi");
const Logger_1 = require("../Logger");
const config_1 = __importDefault(require("../config"));
const redis_service_1 = require("./redis.service");
const MultiMainSetup_ee_1 = require("./orchestration/main/MultiMainSetup.ee");
const n8n_core_1 = require("n8n-core");
let OrchestrationService = class OrchestrationService {
constructor(logger, instanceSettings, redisService, multiMainSetup) {
this.logger = logger;
this.instanceSettings = instanceSettings;
this.redisService = redisService;
this.multiMainSetup = multiMainSetup;
this.isInitialized = false;
this.isMultiMainSetupLicensed = false;
}
setMultiMainSetupLicensed(newState) {
this.isMultiMainSetupLicensed = newState;
}
get isMultiMainSetupEnabled() {
return (config_1.default.getEnv('executions.mode') === 'queue' &&
config_1.default.getEnv('multiMainSetup.enabled') &&
config_1.default.getEnv('generic.instanceType') === 'main' &&
this.isMultiMainSetupLicensed);
}
get isSingleMainSetup() {
return !this.isMultiMainSetupEnabled;
}
get instanceId() {
return config_1.default.getEnv('redis.queueModeId');
}
get isLeader() {
return this.instanceSettings.isLeader;
}
get isFollower() {
return this.instanceSettings.isFollower;
}
sanityCheck() {
return this.isInitialized && config_1.default.get('executions.mode') === 'queue';
}
async init() {
if (this.isInitialized)
return;
if (config_1.default.get('executions.mode') === 'queue')
await this.initPublisher();
if (this.isMultiMainSetupEnabled) {
await this.multiMainSetup.init();
}
else {
this.instanceSettings.markAsLeader();
}
this.isInitialized = true;
}
async shutdown() {
if (!this.isInitialized)
return;
if (this.isMultiMainSetupEnabled)
await this.multiMainSetup.shutdown();
await this.redisPublisher.destroy();
this.isInitialized = false;
}
async initPublisher() {
this.redisPublisher = await this.redisService.getPubSubPublisher();
}
async publish(command, data) {
if (!this.sanityCheck())
return;
const payload = data;
this.logger.debug(`[Instance ID ${this.instanceId}] Publishing command "${command}"`, payload);
await this.redisPublisher.publishToCommandChannel({ command, payload });
}
async getWorkerStatus(id) {
if (!this.sanityCheck())
return;
const command = 'getStatus';
this.logger.debug(`Sending "${command}" to command channel`);
await this.redisPublisher.publishToCommandChannel({
command,
targets: id ? [id] : undefined,
});
}
async getWorkerIds() {
if (!this.sanityCheck())
return;
const command = 'getId';
this.logger.debug(`Sending "${command}" to command channel`);
await this.redisPublisher.publishToCommandChannel({ command });
}
shouldAddWebhooks(activationMode) {
if (activationMode === 'init')
return true;
if (activationMode === 'leadershipChange')
return false;
return this.isLeader;
}
shouldAddTriggersAndPollers() {
return this.isLeader;
}
};
exports.OrchestrationService = OrchestrationService;
exports.OrchestrationService = OrchestrationService = __decorate([
(0, typedi_1.Service)(),
__metadata("design:paramtypes", [Logger_1.Logger,
n8n_core_1.InstanceSettings,
redis_service_1.RedisService,
MultiMainSetup_ee_1.MultiMainSetup])
], OrchestrationService);
//# sourceMappingURL=orchestration.service.js.map