fix(core): Fix isLeader check in WaitTracker constructor (#9100)

This commit is contained in:
Iván Ovejero
2024-04-09 15:50:10 +02:00
committed by GitHub
parent d46635fdb9
commit c2f4d7d796
3 changed files with 27 additions and 11 deletions

View File

@@ -29,16 +29,19 @@ export class WaitTracker {
private readonly workflowRunner: WorkflowRunner, private readonly workflowRunner: WorkflowRunner,
readonly orchestrationService: OrchestrationService, readonly orchestrationService: OrchestrationService,
) { ) {
const { isLeader, isMultiMainSetupEnabled, multiMainSetup } = orchestrationService; const { isSingleMainSetup, isLeader, multiMainSetup } = orchestrationService;
if (isSingleMainSetup) {
this.startTracking();
return;
}
if (isLeader) this.startTracking(); if (isLeader) this.startTracking();
if (isMultiMainSetupEnabled) {
multiMainSetup multiMainSetup
.on('leader-takeover', () => this.startTracking()) .on('leader-takeover', () => this.startTracking())
.on('leader-stepdown', () => this.stopTracking()); .on('leader-stepdown', () => this.stopTracking());
} }
}
startTracking() { startTracking() {
this.logger.debug('Wait tracker started tracking waiting executions'); this.logger.debug('Wait tracker started tracking waiting executions');

View File

@@ -33,6 +33,10 @@ export class OrchestrationService {
); );
} }
get isSingleMainSetup() {
return !this.isMultiMainSetupEnabled;
}
redisPublisher: RedisServicePubSubPublisher; redisPublisher: RedisServicePubSubPublisher;
get instanceId() { 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() { get isLeader() {
return config.getEnv('multiMainSetup.instanceType') === 'leader'; return config.getEnv('multiMainSetup.instanceType') === 'leader';

View File

@@ -10,8 +10,7 @@ jest.useFakeTimers();
describe('WaitTracker', () => { describe('WaitTracker', () => {
const executionRepository = mock<ExecutionRepository>(); const executionRepository = mock<ExecutionRepository>();
const orchestrationService = mock<OrchestrationService>({ const orchestrationService = mock<OrchestrationService>({
isLeader: true, isSingleMainSetup: true,
isMultiMainSetupEnabled: false,
}); });
const execution = mock<IExecutionResponse>({ 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', () => { describe('multi-main setup', () => {
it('should start tracking if leader', () => { it('should start tracking if leader', () => {
const orchestrationService = mock<OrchestrationService>({ const orchestrationService = mock<OrchestrationService>({
isLeader: true, isLeader: true,
isMultiMainSetupEnabled: true, isSingleMainSetup: false,
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }), multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
}); });
@@ -123,7 +132,7 @@ describe('WaitTracker', () => {
it('should not start tracking if follower', () => { it('should not start tracking if follower', () => {
const orchestrationService = mock<OrchestrationService>({ const orchestrationService = mock<OrchestrationService>({
isLeader: false, isLeader: false,
isMultiMainSetupEnabled: true, isSingleMainSetup: false,
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }), multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
}); });