mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
https://linear.app/n8n/issue/PAY-933/set-up-leader-selection-for-multiple-main-instances - [x] Set up new envs - [x] Add config and license checks - [x] Implement `MultiMainInstancePublisher` - [x] Expand `RedisServicePubSubPublisher` to support `MultiMainInstancePublisher` - [x] Init `MultiMainInstancePublisher` on startup and destroy on shutdown - [x] Add to sandbox plans - [x] Test manually Note: This is only for setup - coordinating in reaction to leadership changes will come in later PRs.
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { Logger } from '@/Logger';
|
|
import { Service } from 'typedi';
|
|
import { OrchestrationService } from '@/services/orchestration.base.service';
|
|
|
|
/**
|
|
* For use in main instance, in single main instance scenario.
|
|
*/
|
|
@Service()
|
|
export class SingleMainInstancePublisher extends OrchestrationService {
|
|
constructor(protected readonly logger: Logger) {
|
|
super();
|
|
}
|
|
|
|
sanityCheck() {
|
|
return this.initialized && this.isQueueMode && this.isMainInstance;
|
|
}
|
|
|
|
async getWorkerStatus(id?: string) {
|
|
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 });
|
|
}
|
|
|
|
async broadcastRestartEventbusAfterDestinationUpdate() {
|
|
if (!this.sanityCheck()) return;
|
|
|
|
const command = 'restartEventBus';
|
|
|
|
this.logger.debug(`Sending "${command}" to command channel`);
|
|
|
|
await this.redisPublisher.publishToCommandChannel({ command });
|
|
}
|
|
|
|
async broadcastReloadExternalSecretsProviders() {
|
|
if (!this.sanityCheck()) return;
|
|
|
|
const command = 'reloadExternalSecretsProviders';
|
|
|
|
this.logger.debug(`Sending "${command}" to command channel`);
|
|
|
|
await this.redisPublisher.publishToCommandChannel({ command });
|
|
}
|
|
}
|