mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
af7d293eaf
* Chore: Remove Store interface and use db.DB instead * use old-style session exec
26 lines
497 B
Go
26 lines
497 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
)
|
|
|
|
func (hs *HTTPServer) databaseHealthy(ctx context.Context) bool {
|
|
const cacheKey = "db-healthy"
|
|
|
|
if cached, found := hs.CacheService.Get(cacheKey); found {
|
|
return cached.(bool)
|
|
}
|
|
|
|
err := hs.SQLStore.WithDbSession(ctx, func(session *db.Session) error {
|
|
_, err := session.Exec("SELECT 1")
|
|
return err
|
|
})
|
|
healthy := err == nil
|
|
|
|
hs.CacheService.Set(cacheKey, healthy, time.Second*5)
|
|
return healthy
|
|
}
|