From d018086e565764c0e811621c0aa0a96d7b5e4221 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 8 Jul 2026 17:00:08 +0200 Subject: [PATCH] Add detailed readiness, liveness, and startup health checks with dispatchers and scheduling intervals --- src/main/kotlin/io/github/nomisrev/Main.kt | 9 ++++++++- src/main/kotlin/io/github/nomisrev/env/Dependencies.kt | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/github/nomisrev/Main.kt b/src/main/kotlin/io/github/nomisrev/Main.kt index 1e45d962..fd5eb539 100644 --- a/src/main/kotlin/io/github/nomisrev/Main.kt +++ b/src/main/kotlin/io/github/nomisrev/Main.kt @@ -4,6 +4,7 @@ import arrow.continuations.SuspendApp import arrow.continuations.ktor.server import arrow.fx.coroutines.resourceScope import com.sksamuel.cohort.Cohort +import com.sksamuel.cohort.HealthCheckRegistry import io.github.nomisrev.articles.articleRoutes import io.github.nomisrev.articles.commentRoutes import io.github.nomisrev.env.Dependencies @@ -17,6 +18,7 @@ import io.ktor.server.application.* import io.ktor.server.netty.Netty import io.ktor.server.routing.routing import kotlinx.coroutines.* +import kotlinx.coroutines.Dispatchers fun main() = SuspendApp { val env = Env() @@ -36,5 +38,10 @@ fun Application.app(module: Dependencies) { commentRoutes(module.userService, module.articleService, module.jwtService) profileRoutes(module.userPersistence, module.jwtService) } - install(Cohort) { healthcheck("/readiness", module.healthCheck) } + install(Cohort) { + verboseHealthCheckResponse = developmentMode + healthcheck("/healthz/startup", HealthCheckRegistry(Dispatchers.Default)) + healthcheck("/healthz/liveness", HealthCheckRegistry(Dispatchers.Default)) + healthcheck("/healthz/readiness", module.healthCheck) + } } diff --git a/src/main/kotlin/io/github/nomisrev/env/Dependencies.kt b/src/main/kotlin/io/github/nomisrev/env/Dependencies.kt index 4cc921f2..1194fbe2 100644 --- a/src/main/kotlin/io/github/nomisrev/env/Dependencies.kt +++ b/src/main/kotlin/io/github/nomisrev/env/Dependencies.kt @@ -15,6 +15,9 @@ import io.github.nomisrev.auth.JwtService import io.github.nomisrev.tags.TagPersistence import io.github.nomisrev.users.UserPersistence import io.github.nomisrev.users.UserService +import kotlinx.coroutines.Dispatchers +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds class Dependencies( val userService: UserService, @@ -45,8 +48,8 @@ suspend fun ResourceScope.dependencies(env: Env, hikari: HikariDataSource): Depe val slugGenerator: SlugGenerator = slugifyGenerator() val userService = UserService(userRepo, jwtService) - val checks = HealthCheckRegistry { - register(HikariConnectionsHealthCheck(hikari, minConnections = 1)) + val checks = HealthCheckRegistry(Dispatchers.Default) { + register(HikariConnectionsHealthCheck(hikari, 1), Duration.ZERO, 5.seconds) } return Dependencies(