This commit is contained in:
2026-04-17 14:28:25 +03:00
parent 5759a223d2
commit 89a38eac10
2 changed files with 29 additions and 12 deletions

View File

@@ -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

View File

@@ -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())
.onSuccess(response -> {
if ("PONG".equalsIgnoreCase(response.toString())) {
future.complete(Status.OK());
} else {
future.tryFail("Unexpected Redis response: " + response);
}
})
.onFailure(err -> future.tryFail("Redis ping failed: " + err.getMessage())));
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())) {
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()));
});
// 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);