Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1049: Watchdog should change health status to unhealthy #1163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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");