Skip to content

Commit

Permalink
make tbmq graceful shutdown with env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Nov 21, 2024
1 parent 4b95f6e commit b711fd8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ public static void shutdownAndAwaitTermination(ExecutorService service, long tim
if (service == null) {
return;
}
boolean terminated = MoreExecutors.shutdownAndAwaitTermination(service, Duration.ofSeconds(getTimeoutSeconds(timeoutSeconds)));
long seconds = getTimeoutSeconds(timeoutSeconds);
log.debug("Initiating graceful shutdown of {} executor within {}s", name, seconds);
boolean terminated = MoreExecutors.shutdownAndAwaitTermination(service, Duration.ofSeconds(seconds));
log.info("{} executor termination is: [{}]", name, terminated ? "successful" : "failed");
}

public static long getTimeoutSeconds(long timeoutSeconds) {
return timeoutSeconds > 0 ? timeoutSeconds : 30;
String timeoutEnv = System.getenv("TBMQ_GRACEFUL_SHUTDOWN_TIMEOUT_SEC");
return timeoutSeconds > 0 ? timeoutSeconds : (timeoutEnv == null ? 5 : Long.parseLong(timeoutEnv));
}
}

0 comments on commit b711fd8

Please sign in to comment.