This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ralf-ueberfuhr-ars/feature/observability
Observability
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...-provider/src/main/java/de/schulung/sample/quarkus/infrastructure/LongRunningStartup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package de.schulung.sample.quarkus.infrastructure; | ||
|
||
import io.quarkus.runtime.Startup; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.infrastructure.Infrastructure; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
import org.eclipse.microprofile.health.Readiness; | ||
|
||
@ApplicationScoped | ||
public class LongRunningStartup { | ||
|
||
private volatile boolean initialized = false; | ||
private volatile boolean initializingFailed = false; | ||
|
||
// check during startup: http://localhost:9090/q/health/ready | ||
|
||
private Uni<Void> doLongRunningInitialization() { | ||
try { | ||
Thread.sleep(5000); | ||
initialized = true; | ||
return Uni.createFrom().voidItem(); | ||
} catch (InterruptedException e) { | ||
initializingFailed = true; | ||
return Uni.createFrom().failure(e); | ||
} | ||
} | ||
|
||
@Startup | ||
public void init() { | ||
Uni | ||
.createFrom() | ||
.voidItem() | ||
.emitOn(Infrastructure.getDefaultWorkerPool()) | ||
.subscribe() | ||
.with(v -> this.doLongRunningInitialization()); | ||
} | ||
|
||
@Produces | ||
@ApplicationScoped | ||
@Liveness | ||
public HealthCheck myStartupLiveness() { | ||
return () -> { | ||
final var result = HealthCheckResponse | ||
.named("My long-running startup"); | ||
return (initializingFailed ? result.down() : result.up()).build(); | ||
}; | ||
} | ||
|
||
@Produces | ||
@ApplicationScoped | ||
@Readiness | ||
public HealthCheck myStartupReadyness() { | ||
return () -> { | ||
final var result = HealthCheckResponse | ||
.named("My long-running startup"); | ||
return (initialized ? result.up() : result.down()).build(); | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters