Skip to content

Commit

Permalink
Merge pull request #9 from HSLdevcom/feat/robot_bus
Browse files Browse the repository at this point in the history
Do not use MQTT health check with robot bus
  • Loading branch information
mjaakko authored Jun 16, 2020
2 parents dddd26c + ba9f1a3 commit 72f3326
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/fi/hsl/suomenlinna_hfp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public static void main(String[] args) throws Throwable {

if (config.getBoolean("health.enabled")) {
if (!config.getString("health.postEndpoint").equals("")) {
createHealthServerWithNotification(vehiclePositionProvider, mqttHfpPublisher, config.getString("health.postEndpoint"));
createHealthServerWithNotification(vehiclePositionProvider, mqttHfpPublisher, configType != ConfigType.SBDRIVE, config.getString("health.postEndpoint"));
} else {
createHealthServerWithoutNotification(vehiclePositionProvider, mqttHfpPublisher);
createHealthServerWithoutNotification(vehiclePositionProvider, mqttHfpPublisher, configType != ConfigType.SBDRIVE);
}
}

Expand All @@ -108,15 +108,19 @@ public static ConfigType getByName(String name) {
}
}

private static void createHealthServerWithNotification(VehiclePositionProvider vehiclePositionProvider, MqttHfpPublisher mqttHfpPublisher, String postEndpoint) throws IOException {
private static void createHealthServerWithNotification(VehiclePositionProvider vehiclePositionProvider, MqttHfpPublisher mqttHfpPublisher, boolean publisherHealthCheck, String postEndpoint) throws IOException {
HealthServer healthServer = new HealthServer(8080, new HealthNotificationService(postEndpoint));
healthServer.addCheck(() -> System.nanoTime() - vehiclePositionProvider.getLastReceivedTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
healthServer.addCheck(() -> System.nanoTime() - mqttHfpPublisher.getLastSentTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
if (publisherHealthCheck) {
healthServer.addCheck(() -> System.nanoTime() - mqttHfpPublisher.getLastSentTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
}
}

private static void createHealthServerWithoutNotification(VehiclePositionProvider vehiclePositionProvider, MqttHfpPublisher mqttHfpPublisher) throws IOException {
private static void createHealthServerWithoutNotification(VehiclePositionProvider vehiclePositionProvider, MqttHfpPublisher mqttHfpPublisher, boolean publisherHealthCheck) throws IOException {
HealthServer healthServer = new HealthServer(8080);
healthServer.addCheck(() -> System.nanoTime() - vehiclePositionProvider.getLastReceivedTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
healthServer.addCheck(() -> System.nanoTime() - mqttHfpPublisher.getLastSentTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
if (publisherHealthCheck) {
healthServer.addCheck(() -> System.nanoTime() - mqttHfpPublisher.getLastSentTime() < Duration.of(10, ChronoUnit.MINUTES).toNanos());
}
}
}

0 comments on commit 72f3326

Please sign in to comment.