feat(01-02): add /ready endpoint with database connectivity check
- Add GET /ready endpoint that checks database connection - Returns 200 'ready' when connected, 503 when not - Update Routes to require DataSource dependency - Provide dataSourceLayer in Main.scala - Use 'hikari' prefix for HikariCP config to avoid ZIO config conflict
This commit is contained in:
@@ -1,20 +1,33 @@
|
||||
package api
|
||||
|
||||
import zio.*
|
||||
import zio.http.*
|
||||
import javax.sql.DataSource
|
||||
|
||||
/** Health check endpoints
|
||||
*
|
||||
* Provides basic health check endpoint for load balancers and monitoring systems. The /health
|
||||
* endpoint returns 200 OK when the server is running.
|
||||
* Provides health check endpoints for load balancers and monitoring systems.
|
||||
*
|
||||
* Future endpoints:
|
||||
* - /ready will verify database connectivity
|
||||
* Endpoints:
|
||||
* - GET /health - Returns 200 OK when server is running (liveness probe)
|
||||
* - GET /ready - Returns 200 when database is connected, 503 when not (readiness probe)
|
||||
*/
|
||||
object HealthRoutes {
|
||||
|
||||
val routes: Routes[Any, Response] =
|
||||
val routes: Routes[DataSource, Response] =
|
||||
Routes(
|
||||
Method.GET / "health" -> Handler.text("ok")
|
||||
// Liveness probe - always 200 if server is running
|
||||
Method.GET / "health" -> Handler.text("ok"),
|
||||
// Readiness probe - checks database connectivity
|
||||
Method.GET / "ready" -> handler {
|
||||
ZIO.serviceWithZIO[DataSource] { ds =>
|
||||
ZIO.attempt {
|
||||
val conn = ds.getConnection
|
||||
conn.close()
|
||||
}.as(Response.text("ready"))
|
||||
.catchAll(_ => ZIO.succeed(Response.status(Status.ServiceUnavailable)))
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import zio.http.*
|
||||
import javax.sql.DataSource
|
||||
|
||||
/** Route composition point
|
||||
*
|
||||
@@ -8,7 +9,7 @@ import zio.http.*
|
||||
*/
|
||||
object Routes {
|
||||
|
||||
val routes: Routes[Any, Response] =
|
||||
val routes: Routes[DataSource, Response] =
|
||||
HealthRoutes.routes
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user