Skip to content

Commit 0349a02

Browse files
committed
Timer triggered pipelines are not scheduled on a standby server
* This commit fixes an issue with #5220 which expected the server to be active before scheduling the timer triggered pipelines. With BC addon remains active on startup and on TimerSchduler initialization and later turns inactive on load of the BC jar. * Turning of scheduling timer triggered pipelines for standby server by relying on the SystemEnvironment 'go.server.mode'.
1 parent 6d7320c commit 0349a02

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

base/src/main/java/com/thoughtworks/go/util/SystemEnvironment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ public boolean isProductionMode() {
857857
return GO_SERVER_MODE.getValue().equalsIgnoreCase("production");
858858
}
859859

860+
public boolean isServerInStandbyMode() {
861+
return GO_SERVER_MODE.getValue().equalsIgnoreCase("standby");
862+
}
863+
860864
public boolean isReAuthenticationEnabled() {
861865
return REAUTHENTICATION_ENABLED.getValue();
862866
}

common/src/test/java/com/thoughtworks/go/util/SystemEnvironmentTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,13 @@ public void shouldReturnFalseIfBooleanSystemPropertyIsAnythingButYOrTrue() {
522522
System.setProperty("go.config.repo.gc.periodic", "some-value");
523523
assertThat(new SystemEnvironment().get(SystemEnvironment.GO_CONFIG_REPO_PERIODIC_GC), is(false));
524524
}
525+
526+
@Test
527+
public void shouldBeInStandByModeIfGoServerModeIsSetToStandby() {
528+
assertFalse(new SystemEnvironment().isServerInStandbyMode());
529+
530+
System.setProperty("go.server.mode", "StandBy");
531+
532+
assertTrue(new SystemEnvironment().isServerInStandbyMode());
533+
}
525534
}

server/src/main/java/com/thoughtworks/go/server/service/TimerScheduler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public TimerScheduler(Scheduler scheduler, GoConfigService goConfigService,
7474
}
7575

7676
public void initialize() {
77-
if (!systemEnvironment.isServerActive()) return;
77+
if (systemEnvironment.isServerInStandbyMode()) {
78+
LOG.info("GoCD server in 'standby' mode, skipping scheduling timer triggered pipelines.");
79+
return;
80+
}
7881

7982
scheduleAllJobs(goConfigService.getAllPipelineConfigs());
8083
goConfigService.register(this);

server/src/test-fast/java/com/thoughtworks/go/server/service/TimerSchedulerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ public void shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges() throws Sc
188188
}
189189

190190
@Test
191-
public void shouldNotScheduleJobsOnAnInactiveServer() {
191+
public void shouldNotScheduleJobsForAServerInStandbyMode() {
192192
TimerScheduler timerScheduler = new TimerScheduler(scheduler, goConfigService, null, null, systemEnvironment);
193193

194-
when(systemEnvironment.isServerActive()).thenReturn(false);
194+
when(systemEnvironment.isServerInStandbyMode()).thenReturn(true);
195195

196196
timerScheduler.initialize();
197197

0 commit comments

Comments
 (0)