mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix(core): Fix isLeader
check in WaitTracker
constructor (#9100)
This commit is contained in:
parent
d46635fdb9
commit
c2f4d7d796
|
@ -29,15 +29,18 @@ export class WaitTracker {
|
|||
private readonly workflowRunner: WorkflowRunner,
|
||||
readonly orchestrationService: OrchestrationService,
|
||||
) {
|
||||
const { isLeader, isMultiMainSetupEnabled, multiMainSetup } = orchestrationService;
|
||||
const { isSingleMainSetup, isLeader, multiMainSetup } = orchestrationService;
|
||||
|
||||
if (isSingleMainSetup) {
|
||||
this.startTracking();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLeader) this.startTracking();
|
||||
|
||||
if (isMultiMainSetupEnabled) {
|
||||
multiMainSetup
|
||||
.on('leader-takeover', () => this.startTracking())
|
||||
.on('leader-stepdown', () => this.stopTracking());
|
||||
}
|
||||
multiMainSetup
|
||||
.on('leader-takeover', () => this.startTracking())
|
||||
.on('leader-stepdown', () => this.stopTracking());
|
||||
}
|
||||
|
||||
startTracking() {
|
||||
|
|
|
@ -33,6 +33,10 @@ export class OrchestrationService {
|
|||
);
|
||||
}
|
||||
|
||||
get isSingleMainSetup() {
|
||||
return !this.isMultiMainSetupEnabled;
|
||||
}
|
||||
|
||||
redisPublisher: RedisServicePubSubPublisher;
|
||||
|
||||
get instanceId() {
|
||||
|
@ -40,7 +44,7 @@ export class OrchestrationService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Whether this instance is the leader in a multi-main setup. Always `true` in single-main setup.
|
||||
* Whether this instance is the leader in a multi-main setup. Always `false` in single-main setup.
|
||||
*/
|
||||
get isLeader() {
|
||||
return config.getEnv('multiMainSetup.instanceType') === 'leader';
|
||||
|
|
|
@ -10,8 +10,7 @@ jest.useFakeTimers();
|
|||
describe('WaitTracker', () => {
|
||||
const executionRepository = mock<ExecutionRepository>();
|
||||
const orchestrationService = mock<OrchestrationService>({
|
||||
isLeader: true,
|
||||
isMultiMainSetupEnabled: false,
|
||||
isSingleMainSetup: true,
|
||||
});
|
||||
|
||||
const execution = mock<IExecutionResponse>({
|
||||
|
@ -105,11 +104,21 @@ describe('WaitTracker', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('single-main setup', () => {
|
||||
it('should start tracking', () => {
|
||||
executionRepository.getWaitingExecutions.mockResolvedValue([]);
|
||||
|
||||
new WaitTracker(mock(), executionRepository, mock(), mock(), orchestrationService);
|
||||
|
||||
expect(executionRepository.getWaitingExecutions).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multi-main setup', () => {
|
||||
it('should start tracking if leader', () => {
|
||||
const orchestrationService = mock<OrchestrationService>({
|
||||
isLeader: true,
|
||||
isMultiMainSetupEnabled: true,
|
||||
isSingleMainSetup: false,
|
||||
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
|
||||
});
|
||||
|
||||
|
@ -123,7 +132,7 @@ describe('WaitTracker', () => {
|
|||
it('should not start tracking if follower', () => {
|
||||
const orchestrationService = mock<OrchestrationService>({
|
||||
isLeader: false,
|
||||
isMultiMainSetupEnabled: true,
|
||||
isSingleMainSetup: false,
|
||||
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue