Skip to content
Permalink
Browse files
1049: Watchdog should change health status to unhealthy
Reviewed-by: kcr, ehelin
  • Loading branch information
erikj79 committed May 24, 2021
1 parent c1f8697 commit bcf27471dc8894475c1b298878b05e60b31ba131
Showing 2 changed files with 8 additions and 3 deletions.
@@ -213,6 +213,7 @@ private void drain(Duration timeout) throws TimeoutException {
private final BotWatchdog botWatchdog;
private final Duration watchdogWarnTimeout;
private volatile boolean isReady;
private volatile boolean isHealthy;

private static final Logger log = Logger.getLogger("org.openjdk.skara.bot");

@@ -230,17 +231,18 @@ public BotRunner(BotRunnerConfiguration config, List<Bot> bots) {
}

executor = new ScheduledThreadPoolExecutor(config.concurrency());
botWatchdog = new BotWatchdog(config.watchdogTimeout());
botWatchdog = new BotWatchdog(config.watchdogTimeout(), () -> isHealthy = false);
watchdogWarnTimeout = config.watchdogWarnTimeout();
isReady = false;
isHealthy = true;
}

boolean isReady() {
return isReady;
}

boolean isHealthy() {
return true;
return isHealthy;
}

private void checkPeriodicItems() {
@@ -28,6 +28,7 @@ public class BotWatchdog {
private final Thread watchThread;
private final long maxWaitMillis;
private final Duration maxWait;
private final Runnable callBack;
private volatile boolean hasBeenPinged = false;

private void threadMain() {
@@ -36,6 +37,7 @@ private void threadMain() {
Thread.sleep(maxWaitMillis);
if (!hasBeenPinged) {
System.out.println("No watchdog ping detected for " + maxWait + " - exiting...");
callBack.run();
System.exit(1);
}
hasBeenPinged = false;
@@ -44,8 +46,9 @@ private void threadMain() {
}
}

BotWatchdog(Duration maxWait) {
BotWatchdog(Duration maxWait, Runnable callBack) {
this.maxWait = maxWait;
this.callBack = callBack;
maxWaitMillis = maxWait.toMillis();
watchThread = new Thread(this::threadMain);
watchThread.setName("BotWatchdog");

1 comment on commit bcf2747

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on bcf2747 May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.