org.jobrunr.spring.autoconfigure.health.JobRunrHealthIndicator Maven / Gradle / Ivy
package org.jobrunr.spring.autoconfigure.health;
import org.jobrunr.server.BackgroundJobServer;
import org.jobrunr.spring.autoconfigure.JobRunrProperties;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
public class JobRunrHealthIndicator implements HealthIndicator {
private final ObjectProvider backgroundJobServerProvider;
private final JobRunrProperties jobRunrProperties;
public JobRunrHealthIndicator(JobRunrProperties jobRunrProperties, ObjectProvider backgroundJobServerProvider) {
this.jobRunrProperties = jobRunrProperties;
this.backgroundJobServerProvider = backgroundJobServerProvider;
}
@Override
public Health health() {
final Health.Builder health = Health.unknown();
if (!jobRunrProperties.getBackgroundJobServer().isEnabled()) {
health
.up()
.withDetail("backgroundJobServer", "disabled");
} else {
final BackgroundJobServer backgroundJobServer = backgroundJobServerProvider.getIfAvailable();
if (backgroundJobServer.isRunning()) {
health
.up()
.withDetail("backgroundJobServer", "enabled")
.withDetail("backgroundJobServerStatus", "running");
} else {
health
.down()
.withDetail("backgroundJobServer", "enabled")
.withDetail("backgroundJobServerStatus", "stopped");
}
}
return health.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy