Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/kotlin/io/github/nomisrev/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
}
}
7 changes: 5 additions & 2 deletions src/main/kotlin/io/github/nomisrev/env/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Loading