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-web-sstore-redis")
implementation("io.vertx:vertx-mail-client") implementation("io.vertx:vertx-mail-client")
implementation("com.fasterxml.jackson.core:jackson-databind")
// https://mvnrepository.com/artifact/org.mindrot/jbcrypt // https://mvnrepository.com/artifact/org.mindrot/jbcrypt
implementation("org.mindrot:jbcrypt:0.4") implementation("org.mindrot:jbcrypt:0.4")
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api // https://mvnrepository.com/artifact/org.slf4j/slf4j-api

View File

@@ -1,6 +1,7 @@
package su.xserver.iikocon.service; package su.xserver.iikocon.service;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.healthchecks.Status; import io.vertx.ext.healthchecks.Status;
import io.vertx.ext.web.Router; import io.vertx.ext.web.Router;
import io.vertx.ext.web.healthchecks.HealthCheckHandler; import io.vertx.ext.web.healthchecks.HealthCheckHandler;
@@ -23,20 +24,34 @@ public class HealthCheckService {
HealthCheckHandler healthCheckHandler = HealthCheckHandler.create(vertx); HealthCheckHandler healthCheckHandler = HealthCheckHandler.create(vertx);
// Redis check // Redis check
healthCheckHandler.register("redis", future -> redisService.getRedisApi().ping(Collections.emptyList()) healthCheckHandler.register("redis", future -> {
.onSuccess(response -> { long start = System.currentTimeMillis();
if ("PONG".equalsIgnoreCase(response.toString())) { redisService.getRedisApi().ping(Collections.emptyList())
future.complete(Status.OK()); .onSuccess(response -> {
} else { long time = System.currentTimeMillis() - start;
future.tryFail("Unexpected Redis response: " + response); if ("PONG".equalsIgnoreCase(response.toString())) {
} JsonObject data = new JsonObject()
}) .put("latency_ms", time);
.onFailure(err -> future.tryFail("Redis ping failed: " + err.getMessage()))); future.complete(Status.OK(data));
} else {
future.tryFail("Unexpected Redis response: " + response);
}
})
.onFailure(err -> future.tryFail("Redis ping failed: " + err.getMessage()));
});
// Database check // Database check
healthCheckHandler.register("database", future -> dbService.getPool().query("SELECT 1").execute() healthCheckHandler.register("database", future -> {
.onSuccess(rs -> future.complete(Status.OK())) long start = System.currentTimeMillis();
.onFailure(t -> future.fail("Database is not reachable: " + t.getMessage()))); 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 // Регистрируем endpoint /health
router.get("/health").handler(healthCheckHandler); router.get("/health").handler(healthCheckHandler);