mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-22 07:02:27 -04:00
Add /health and /ready for transcoder
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type health struct {
|
||||
db *pgxpool.Pool
|
||||
}
|
||||
|
||||
func RegisterHealthHandlers(e *echo.Group, db *pgxpool.Pool) {
|
||||
h := health{db}
|
||||
e.GET("/health", h.CheckHealth)
|
||||
e.GET("/ready", h.CheckReady)
|
||||
}
|
||||
|
||||
func (h *health) CheckHealth(c echo.Context) error {
|
||||
return c.JSON(200, struct {
|
||||
Status string `json:"status"`
|
||||
}{Status: "healthy"})
|
||||
}
|
||||
|
||||
func (h *health) CheckReady(c echo.Context) error {
|
||||
_, err := h.db.Exec(c.Request().Context(), "select 1")
|
||||
|
||||
status := "healthy"
|
||||
db := "healthy"
|
||||
ret := 200
|
||||
if err != nil {
|
||||
status = "unhealthy"
|
||||
ret = 500
|
||||
db = err.Error()
|
||||
}
|
||||
|
||||
return c.JSON(ret, struct {
|
||||
Status string `json:"status"`
|
||||
Database string `json:"database"`
|
||||
}{Status: status, Database: db})
|
||||
}
|
||||
Reference in New Issue
Block a user