Skip to content

Commit 549e8f7

Browse files
ivovnetroy
authored andcommitted
fix(core): Fix isLeader check in WaitTracker constructor (#9100)
1 parent 3992ae7 commit 549e8f7

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

packages/cli/src/WaitTracker.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ export class WaitTracker {
2929
private readonly workflowRunner: WorkflowRunner,
3030
readonly orchestrationService: OrchestrationService,
3131
) {
32-
const { isLeader, isMultiMainSetupEnabled, multiMainSetup } = orchestrationService;
32+
const { isSingleMainSetup, isLeader, multiMainSetup } = orchestrationService;
33+
34+
if (isSingleMainSetup) {
35+
this.startTracking();
36+
return;
37+
}
3338

3439
if (isLeader) this.startTracking();
3540

36-
if (isMultiMainSetupEnabled) {
37-
multiMainSetup
38-
.on('leader-takeover', () => this.startTracking())
39-
.on('leader-stepdown', () => this.stopTracking());
40-
}
41+
multiMainSetup
42+
.on('leader-takeover', () => this.startTracking())
43+
.on('leader-stepdown', () => this.stopTracking());
4144
}
4245

4346
startTracking() {

packages/cli/src/services/orchestration.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ export class OrchestrationService {
3333
);
3434
}
3535

36+
get isSingleMainSetup() {
37+
return !this.isMultiMainSetupEnabled;
38+
}
39+
3640
redisPublisher: RedisServicePubSubPublisher;
3741

3842
get instanceId() {
3943
return config.getEnv('redis.queueModeId');
4044
}
4145

4246
/**
43-
* Whether this instance is the leader in a multi-main setup. Always `true` in single-main setup.
47+
* Whether this instance is the leader in a multi-main setup. Always `false` in single-main setup.
4448
*/
4549
get isLeader() {
4650
return config.getEnv('multiMainSetup.instanceType') === 'leader';

packages/cli/test/unit/WaitTracker.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jest.useFakeTimers();
1010
describe('WaitTracker', () => {
1111
const executionRepository = mock<ExecutionRepository>();
1212
const orchestrationService = mock<OrchestrationService>({
13-
isLeader: true,
14-
isMultiMainSetupEnabled: false,
13+
isSingleMainSetup: true,
1514
});
1615

1716
const execution = mock<IExecutionResponse>({
@@ -105,11 +104,21 @@ describe('WaitTracker', () => {
105104
});
106105
});
107106

107+
describe('single-main setup', () => {
108+
it('should start tracking', () => {
109+
executionRepository.getWaitingExecutions.mockResolvedValue([]);
110+
111+
new WaitTracker(mock(), executionRepository, mock(), mock(), orchestrationService);
112+
113+
expect(executionRepository.getWaitingExecutions).toHaveBeenCalledTimes(1);
114+
});
115+
});
116+
108117
describe('multi-main setup', () => {
109118
it('should start tracking if leader', () => {
110119
const orchestrationService = mock<OrchestrationService>({
111120
isLeader: true,
112-
isMultiMainSetupEnabled: true,
121+
isSingleMainSetup: false,
113122
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
114123
});
115124

@@ -123,7 +132,7 @@ describe('WaitTracker', () => {
123132
it('should not start tracking if follower', () => {
124133
const orchestrationService = mock<OrchestrationService>({
125134
isLeader: false,
126-
isMultiMainSetupEnabled: true,
135+
isSingleMainSetup: false,
127136
multiMainSetup: mock<MultiMainSetup>({ on: jest.fn().mockReturnThis() }),
128137
});
129138

0 commit comments

Comments
 (0)