2020-10-21 04:06:19 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-10-11 07:35:03 -05:00
|
|
|
"context"
|
2020-10-21 04:06:19 -05:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
2021-10-11 07:35:03 -05:00
|
|
|
func (hs *HTTPServer) databaseHealthy(ctx context.Context) bool {
|
2020-10-21 04:06:19 -05:00
|
|
|
const cacheKey = "db-healthy"
|
|
|
|
|
|
|
|
if cached, found := hs.CacheService.Get(cacheKey); found {
|
|
|
|
return cached.(bool)
|
|
|
|
}
|
|
|
|
|
2022-02-04 07:33:35 -06:00
|
|
|
healthy := hs.SQLStore.GetDBHealthQuery(ctx, &models.GetDBHealthQuery{}) == nil
|
2020-10-21 04:06:19 -05:00
|
|
|
|
|
|
|
hs.CacheService.Set(cacheKey, healthy, time.Second*5)
|
|
|
|
return healthy
|
|
|
|
}
|