Add health check
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -86,6 +86,10 @@
|
|||||||
<version>${record-builder.version}</version>
|
<version>${record-builder.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-smallrye-health</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-junit</artifactId>
|
<artifactId>quarkus-junit</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.backend.unifier.title.service.health;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import org.eclipse.microprofile.health.HealthCheck;
|
||||||
|
import org.eclipse.microprofile.health.HealthCheckResponse;
|
||||||
|
import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
|
||||||
|
import org.eclipse.microprofile.health.Readiness;
|
||||||
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||||
|
|
||||||
|
import com.backend.metadata.kodik.service.api.model.KodikResponse;
|
||||||
|
import com.backend.unifier.title.service.api.KodikSearchService;
|
||||||
|
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
@Readiness
|
||||||
|
@ApplicationScoped
|
||||||
|
public class KodikServiceHealthCheck implements HealthCheck {
|
||||||
|
@RestClient
|
||||||
|
KodikSearchService kodikService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HealthCheckResponse call() {
|
||||||
|
HealthCheckResponseBuilder responseBuilder = HealthCheckResponse.named("Kodik Service Connection");
|
||||||
|
|
||||||
|
try {
|
||||||
|
KodikResponse response = kodikService.search("Хеллсинг");
|
||||||
|
|
||||||
|
return responseBuilder
|
||||||
|
.up()
|
||||||
|
.withData("status", "connected")
|
||||||
|
.withData("timestamp", Instant.now().toString())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return responseBuilder
|
||||||
|
.down()
|
||||||
|
.withData("reason", e.getMessage())
|
||||||
|
.withData("timestamp", Instant.now().toString())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user