Fix healthcheck
This commit is contained in:
parent
36c04e656d
commit
f7981715db
4 changed files with 53 additions and 14 deletions
|
@ -3,6 +3,7 @@ package handlers
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"git.agecem.com/agecem/bottin-agenda/data"
|
||||
bottindata "git.agecem.com/agecem/bottin/v5/data"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -30,8 +31,26 @@ func GetHealth(c echo.Context) error {
|
|||
bottinStatus = healthResponse
|
||||
}
|
||||
|
||||
var databaseStatus string
|
||||
|
||||
// Check database is ready
|
||||
|
||||
dataClient, err := data.NewDataClientFromViper()
|
||||
if err != nil {
|
||||
databaseStatus = err.Error()
|
||||
} else {
|
||||
defer dataClient.DB.Close()
|
||||
|
||||
if err := dataClient.DB.Ping(); err != nil {
|
||||
databaseStatus = err.Error()
|
||||
} else {
|
||||
databaseStatus = "Bottin-agenda database is ready"
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{
|
||||
"message": "Bottin-agenda API v2 is ready",
|
||||
"bottin": bottinStatus,
|
||||
"message": "Bottin-agenda API v2 is ready",
|
||||
"bottin": bottinStatus,
|
||||
"database": databaseStatus,
|
||||
})
|
||||
}
|
||||
|
|
Reference in a new issue