Skip to content

Commit 1a2c230

Browse files
committed
Add detailed readiness, liveness, and startup health checks with dispatchers and scheduling intervals
1 parent 6368068 commit 1a2c230

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/kotlin/io/github/nomisrev/Main.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import arrow.continuations.SuspendApp
44
import arrow.continuations.ktor.server
55
import arrow.fx.coroutines.resourceScope
66
import com.sksamuel.cohort.Cohort
7+
import com.sksamuel.cohort.HealthCheckRegistry
78
import io.github.nomisrev.articles.articleRoutes
89
import io.github.nomisrev.articles.commentRoutes
910
import io.github.nomisrev.env.Dependencies
@@ -17,6 +18,7 @@ import io.ktor.server.application.*
1718
import io.ktor.server.netty.Netty
1819
import io.ktor.server.routing.routing
1920
import kotlinx.coroutines.*
21+
import kotlinx.coroutines.Dispatchers
2022

2123
fun main() = SuspendApp {
2224
val env = Env()
@@ -36,5 +38,10 @@ fun Application.app(module: Dependencies) {
3638
commentRoutes(module.userService, module.articleService, module.jwtService)
3739
profileRoutes(module.userPersistence, module.jwtService)
3840
}
39-
install(Cohort) { healthcheck("/readiness", module.healthCheck) }
41+
install(Cohort) {
42+
verboseHealthCheckResponse = developmentMode
43+
healthcheck("/healthz/startup", HealthCheckRegistry(Dispatchers.Default))
44+
healthcheck("/healthz/liveness", HealthCheckRegistry(Dispatchers.Default))
45+
healthcheck("/healthz/readiness", module.healthCheck)
46+
}
4047
}

src/main/kotlin/io/github/nomisrev/env/Dependencies.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import io.github.nomisrev.auth.JwtService
1414
import io.github.nomisrev.tags.TagPersistence
1515
import io.github.nomisrev.users.UserPersistence
1616
import io.github.nomisrev.users.UserService
17+
import kotlinx.coroutines.Dispatchers
18+
import kotlin.time.Duration
19+
import kotlin.time.Duration.Companion.seconds
1720

1821
class Dependencies(
1922
val userService: UserService,
@@ -42,8 +45,8 @@ suspend fun ResourceScope.dependencies(env: Env): Dependencies {
4245
val slugGenerator: SlugGenerator = slugifyGenerator()
4346
val userService = UserService(userRepo, jwtService)
4447

45-
val checks = HealthCheckRegistry {
46-
register(HikariConnectionsHealthCheck(hikari, minConnections = 1))
48+
val checks = HealthCheckRegistry(Dispatchers.Default) {
49+
register(HikariConnectionsHealthCheck(hikari, 1), Duration.ZERO, 5.seconds)
4750
}
4851

4952
return Dependencies(

0 commit comments

Comments
 (0)