+ up
This commit is contained in:
@@ -36,6 +36,8 @@ dependencies {
|
||||
implementation("io.vertx:vertx-web-sstore-redis")
|
||||
implementation("io.vertx:vertx-mail-client")
|
||||
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind")
|
||||
|
||||
// https://mvnrepository.com/artifact/org.mindrot/jbcrypt
|
||||
implementation("org.mindrot:jbcrypt:0.4")
|
||||
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package su.xserver.iikocon.service;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.healthchecks.Status;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.healthchecks.HealthCheckHandler;
|
||||
@@ -23,20 +24,34 @@ public class HealthCheckService {
|
||||
HealthCheckHandler healthCheckHandler = HealthCheckHandler.create(vertx);
|
||||
|
||||
// Redis check
|
||||
healthCheckHandler.register("redis", future -> redisService.getRedisApi().ping(Collections.emptyList())
|
||||
healthCheckHandler.register("redis", future -> {
|
||||
long start = System.currentTimeMillis();
|
||||
redisService.getRedisApi().ping(Collections.emptyList())
|
||||
.onSuccess(response -> {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
if ("PONG".equalsIgnoreCase(response.toString())) {
|
||||
future.complete(Status.OK());
|
||||
JsonObject data = new JsonObject()
|
||||
.put("latency_ms", time);
|
||||
future.complete(Status.OK(data));
|
||||
} else {
|
||||
future.tryFail("Unexpected Redis response: " + response);
|
||||
}
|
||||
})
|
||||
.onFailure(err -> future.tryFail("Redis ping failed: " + err.getMessage())));
|
||||
.onFailure(err -> future.tryFail("Redis ping failed: " + err.getMessage()));
|
||||
});
|
||||
|
||||
// Database check
|
||||
healthCheckHandler.register("database", future -> dbService.getPool().query("SELECT 1").execute()
|
||||
.onSuccess(rs -> future.complete(Status.OK()))
|
||||
.onFailure(t -> future.fail("Database is not reachable: " + t.getMessage())));
|
||||
healthCheckHandler.register("database", future -> {
|
||||
long start = System.currentTimeMillis();
|
||||
dbService.getPool().query("SELECT 1").execute()
|
||||
.onSuccess(rs -> {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
JsonObject data = new JsonObject()
|
||||
.put("latency_ms", time);
|
||||
future.complete(Status.OK(data));
|
||||
})
|
||||
.onFailure(err -> future.tryFail("DataBase ping failed: " + err.getMessage()));
|
||||
});
|
||||
|
||||
// Регистрируем endpoint /health
|
||||
router.get("/health").handler(healthCheckHandler);
|
||||
|
||||
Reference in New Issue
Block a user