mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Make instance role clearer (no-changelog) (#10188)
This commit is contained in:
@@ -55,7 +55,7 @@ export class License {
|
|||||||
* This ensures the mains do not cause a 429 (too many requests) on license init.
|
* This ensures the mains do not cause a 429 (too many requests) on license init.
|
||||||
*/
|
*/
|
||||||
if (config.getEnv('multiMainSetup.enabled')) {
|
if (config.getEnv('multiMainSetup.enabled')) {
|
||||||
return autoRenewEnabled && config.getEnv('multiMainSetup.instanceType') === 'leader';
|
return autoRenewEnabled && config.getEnv('instanceRole') === 'leader';
|
||||||
}
|
}
|
||||||
|
|
||||||
return autoRenewEnabled;
|
return autoRenewEnabled;
|
||||||
|
|||||||
@@ -184,10 +184,7 @@ export class Start extends BaseCommand {
|
|||||||
await this.initOrchestration();
|
await this.initOrchestration();
|
||||||
this.logger.debug('Orchestration init complete');
|
this.logger.debug('Orchestration init complete');
|
||||||
|
|
||||||
if (
|
if (!config.getEnv('license.autoRenewEnabled') && config.getEnv('instanceRole') === 'leader') {
|
||||||
!config.getEnv('license.autoRenewEnabled') &&
|
|
||||||
config.getEnv('multiMainSetup.instanceType') === 'leader'
|
|
||||||
) {
|
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
'Automatic license renewal is disabled. The license will not renew automatically, and access to licensed features may be lost!',
|
'Automatic license renewal is disabled. The license will not renew automatically, and access to licensed features may be lost!',
|
||||||
);
|
);
|
||||||
@@ -211,7 +208,7 @@ export class Start extends BaseCommand {
|
|||||||
|
|
||||||
async initOrchestration() {
|
async initOrchestration() {
|
||||||
if (config.getEnv('executions.mode') === 'regular') {
|
if (config.getEnv('executions.mode') === 'regular') {
|
||||||
config.set('multiMainSetup.instanceType', 'leader');
|
config.set('instanceRole', 'leader');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -883,12 +883,13 @@ export const schema = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
multiMainSetup: {
|
instanceRole: {
|
||||||
instanceType: {
|
doc: 'Always `leader` in single-main setup. `leader` or `follower` in multi-main setup.',
|
||||||
doc: 'Type of instance in multi-main setup',
|
|
||||||
format: ['unset', 'leader', 'follower'] as const,
|
format: ['unset', 'leader', 'follower'] as const,
|
||||||
default: 'unset', // only until first leader key check
|
default: 'unset', // only until Start.initOrchestration
|
||||||
},
|
},
|
||||||
|
|
||||||
|
multiMainSetup: {
|
||||||
enabled: {
|
enabled: {
|
||||||
doc: 'Whether to enable multi-main setup for queue mode (license required)',
|
doc: 'Whether to enable multi-main setup for queue mode (license required)',
|
||||||
format: Boolean,
|
format: Boolean,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ describe('ExecutionRecoveryService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config.set('multiMainSetup.instanceType', 'leader');
|
config.set('instanceRole', 'leader');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -130,7 +130,7 @@ describe('ExecutionRecoveryService', () => {
|
|||||||
/**
|
/**
|
||||||
* Arrange
|
* Arrange
|
||||||
*/
|
*/
|
||||||
config.set('multiMainSetup.instanceType', 'follower');
|
config.set('instanceRole', 'follower');
|
||||||
// @ts-expect-error Private method
|
// @ts-expect-error Private method
|
||||||
const amendSpy = jest.spyOn(executionRecoveryService, 'amend');
|
const amendSpy = jest.spyOn(executionRecoveryService, 'amend');
|
||||||
const messages = setupMessages('123', 'Some workflow');
|
const messages = setupMessages('123', 'Some workflow');
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ export class ExecutionRecoveryService {
|
|||||||
private shouldScheduleQueueRecovery() {
|
private shouldScheduleQueueRecovery() {
|
||||||
return (
|
return (
|
||||||
config.getEnv('executions.mode') === 'queue' &&
|
config.getEnv('executions.mode') === 'queue' &&
|
||||||
config.getEnv('multiMainSetup.instanceType') === 'leader' &&
|
config.getEnv('instanceRole') === 'leader' &&
|
||||||
!this.isShuttingDown
|
!this.isShuttingDown
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,15 +43,12 @@ export class OrchestrationService {
|
|||||||
return config.getEnv('redis.queueModeId');
|
return config.getEnv('redis.queueModeId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this instance is the leader in a multi-main setup. Always `false` in single-main setup.
|
|
||||||
*/
|
|
||||||
get isLeader() {
|
get isLeader() {
|
||||||
return config.getEnv('multiMainSetup.instanceType') === 'leader';
|
return config.getEnv('instanceRole') === 'leader';
|
||||||
}
|
}
|
||||||
|
|
||||||
get isFollower() {
|
get isFollower() {
|
||||||
return config.getEnv('multiMainSetup.instanceType') !== 'leader';
|
return config.getEnv('instanceRole') !== 'leader';
|
||||||
}
|
}
|
||||||
|
|
||||||
sanityCheck() {
|
sanityCheck() {
|
||||||
@@ -66,7 +63,7 @@ export class OrchestrationService {
|
|||||||
if (this.isMultiMainSetupEnabled) {
|
if (this.isMultiMainSetupEnabled) {
|
||||||
await this.multiMainSetup.init();
|
await this.multiMainSetup.init();
|
||||||
} else {
|
} else {
|
||||||
config.set('multiMainSetup.instanceType', 'leader');
|
config.set('instanceRole', 'leader');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export class MultiMainSetup extends EventEmitter {
|
|||||||
async shutdown() {
|
async shutdown() {
|
||||||
clearInterval(this.leaderCheckInterval);
|
clearInterval(this.leaderCheckInterval);
|
||||||
|
|
||||||
const isLeader = config.getEnv('multiMainSetup.instanceType') === 'leader';
|
const isLeader = config.getEnv('instanceRole') === 'leader';
|
||||||
|
|
||||||
if (isLeader) await this.redisPublisher.clear(this.leaderKey);
|
if (isLeader) await this.redisPublisher.clear(this.leaderKey);
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ export class MultiMainSetup extends EventEmitter {
|
|||||||
if (leaderId && leaderId !== this.instanceId) {
|
if (leaderId && leaderId !== this.instanceId) {
|
||||||
this.logger.debug(`[Instance ID ${this.instanceId}] Leader is other instance "${leaderId}"`);
|
this.logger.debug(`[Instance ID ${this.instanceId}] Leader is other instance "${leaderId}"`);
|
||||||
|
|
||||||
if (config.getEnv('multiMainSetup.instanceType') === 'leader') {
|
if (config.getEnv('instanceRole') === 'leader') {
|
||||||
config.set('multiMainSetup.instanceType', 'follower');
|
config.set('instanceRole', 'follower');
|
||||||
|
|
||||||
this.emit('leader-stepdown'); // lost leadership - stop triggers, pollers, pruning, wait-tracking, queue recovery
|
this.emit('leader-stepdown'); // lost leadership - stop triggers, pollers, pruning, wait-tracking, queue recovery
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ export class MultiMainSetup extends EventEmitter {
|
|||||||
`[Instance ID ${this.instanceId}] Leadership vacant, attempting to become leader...`,
|
`[Instance ID ${this.instanceId}] Leadership vacant, attempting to become leader...`,
|
||||||
);
|
);
|
||||||
|
|
||||||
config.set('multiMainSetup.instanceType', 'follower');
|
config.set('instanceRole', 'follower');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lost leadership - stop triggers, pollers, pruning, wait tracking, license renewal, queue recovery
|
* Lost leadership - stop triggers, pollers, pruning, wait tracking, license renewal, queue recovery
|
||||||
@@ -101,7 +101,7 @@ export class MultiMainSetup extends EventEmitter {
|
|||||||
if (keySetSuccessfully) {
|
if (keySetSuccessfully) {
|
||||||
this.logger.debug(`[Instance ID ${this.instanceId}] Leader is now this instance`);
|
this.logger.debug(`[Instance ID ${this.instanceId}] Leader is now this instance`);
|
||||||
|
|
||||||
config.set('multiMainSetup.instanceType', 'leader');
|
config.set('instanceRole', 'leader');
|
||||||
|
|
||||||
await this.redisPublisher.setExpiration(this.leaderKey, this.leaderKeyTtl);
|
await this.redisPublisher.setExpiration(this.leaderKey, this.leaderKeyTtl);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ export class MultiMainSetup extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.emit('leader-takeover');
|
this.emit('leader-takeover');
|
||||||
} else {
|
} else {
|
||||||
config.set('multiMainSetup.instanceType', 'follower');
|
config.set('instanceRole', 'follower');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export class PruningService {
|
|||||||
if (
|
if (
|
||||||
config.getEnv('multiMainSetup.enabled') &&
|
config.getEnv('multiMainSetup.enabled') &&
|
||||||
config.getEnv('generic.instanceType') === 'main' &&
|
config.getEnv('generic.instanceType') === 'main' &&
|
||||||
config.getEnv('multiMainSetup.instanceType') === 'follower'
|
config.getEnv('instanceRole') === 'follower'
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ describe('Orchestration Service', () => {
|
|||||||
|
|
||||||
describe('shouldAddWebhooks', () => {
|
describe('shouldAddWebhooks', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
config.set('multiMainSetup.instanceType', 'leader');
|
config.set('instanceRole', 'leader');
|
||||||
});
|
});
|
||||||
test('should return true for init', () => {
|
test('should return true for init', () => {
|
||||||
// We want to ensure that webhooks are populated on init
|
// We want to ensure that webhooks are populated on init
|
||||||
@@ -169,7 +169,7 @@ describe('Orchestration Service', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should return false for update or activate when not leader', () => {
|
test('should return false for update or activate when not leader', () => {
|
||||||
config.set('multiMainSetup.instanceType', 'follower');
|
config.set('instanceRole', 'follower');
|
||||||
const modes = ['update', 'activate'] as WorkflowActivateMode[];
|
const modes = ['update', 'activate'] as WorkflowActivateMode[];
|
||||||
for (const mode of modes) {
|
for (const mode of modes) {
|
||||||
const result = os.shouldAddWebhooks(mode);
|
const result = os.shouldAddWebhooks(mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user