Change healthchecker to return error
This commit is contained in:
		| @@ -109,6 +109,6 @@ func (s *CachingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) | ||||
| 	return attempts, err | ||||
| } | ||||
|  | ||||
| func (s *CachingStore) IsHealthy() bool { | ||||
| func (s *CachingStore) IsHealthy() error { | ||||
| 	return s.backend.IsHealthy() | ||||
| } | ||||
|   | ||||
| @@ -142,8 +142,8 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) | ||||
| 	return results, nil | ||||
| } | ||||
|  | ||||
| func (s *MemoryStore) IsHealthy() bool { | ||||
| 	return true | ||||
| func (s *MemoryStore) IsHealthy() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func toResults(m map[string]int) []StatsResult { | ||||
|   | ||||
| @@ -121,6 +121,6 @@ func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttemp | ||||
| 	return s.store.Query(query) | ||||
| } | ||||
|  | ||||
| func (s *MetricsCollectingStore) IsHealthy() bool { | ||||
| 	return s.IsHealthy() | ||||
| func (s *MetricsCollectingStore) IsHealthy() error { | ||||
| 	return s.store.IsHealthy() | ||||
| } | ||||
|   | ||||
| @@ -126,8 +126,11 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er | ||||
| 	return results, nil | ||||
| } | ||||
|  | ||||
| func (s *PostgresStore) IsHealthy() bool { | ||||
| 	return s.db.Ping() == nil | ||||
| func (s *PostgresStore) IsHealthy() error { | ||||
| 	if err := s.db.Ping(); err != nil { | ||||
| 		return ErrStoreUnhealthy | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { | ||||
|   | ||||
| @@ -1,6 +1,12 @@ | ||||
| package store | ||||
|  | ||||
| import "github.uio.no/torjus/apiary/models" | ||||
| import ( | ||||
| 	"errors" | ||||
|  | ||||
| 	"github.uio.no/torjus/apiary/models" | ||||
| ) | ||||
|  | ||||
| var ErrStoreUnhealthy = errors.New("store is unhealthy") | ||||
|  | ||||
| type LoginStats string | ||||
|  | ||||
| @@ -39,5 +45,5 @@ type LoginAttemptStore interface { | ||||
| } | ||||
|  | ||||
| type HealthCheker interface { | ||||
| 	IsHealthy() bool | ||||
| 	IsHealthy() error | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user