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 | 	return attempts, err | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *CachingStore) IsHealthy() bool { | func (s *CachingStore) IsHealthy() error { | ||||||
| 	return s.backend.IsHealthy() | 	return s.backend.IsHealthy() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -142,8 +142,8 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *MemoryStore) IsHealthy() bool { | func (s *MemoryStore) IsHealthy() error { | ||||||
| 	return true | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func toResults(m map[string]int) []StatsResult { | func toResults(m map[string]int) []StatsResult { | ||||||
|   | |||||||
| @@ -121,6 +121,6 @@ func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttemp | |||||||
| 	return s.store.Query(query) | 	return s.store.Query(query) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *MetricsCollectingStore) IsHealthy() bool { | func (s *MetricsCollectingStore) IsHealthy() error { | ||||||
| 	return s.IsHealthy() | 	return s.store.IsHealthy() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -126,8 +126,11 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *PostgresStore) IsHealthy() bool { | func (s *PostgresStore) IsHealthy() error { | ||||||
| 	return s.db.Ping() == nil | 	if err := s.db.Ping(); err != nil { | ||||||
|  | 		return ErrStoreUnhealthy | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { | func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { | ||||||
|   | |||||||
| @@ -1,6 +1,12 @@ | |||||||
| package store | 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 | type LoginStats string | ||||||
|  |  | ||||||
| @@ -39,5 +45,5 @@ type LoginAttemptStore interface { | |||||||
| } | } | ||||||
|  |  | ||||||
| type HealthCheker interface { | type HealthCheker interface { | ||||||
| 	IsHealthy() bool | 	IsHealthy() error | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user