Documentation
¶
Index ¶
- Constants
- type ContributorHealth
- type HealthState
- type Manager
- func (m *Manager) GetAllHealth() map[string]ContributorHealth
- func (m *Manager) GetHealth(name string) *ContributorHealth
- func (m *Manager) IsHealthy(name string) bool
- func (m *Manager) RecordFailure(name string, err error)
- func (m *Manager) RecordSuccess(name string)
- func (m *Manager) Remove(name string)
- func (m *Manager) SetOnStateChange(fn func(name string, oldState, newState HealthState))
Constants ¶
const ( DegradedThreshold = 2 // consecutive failures before degraded DownThreshold = 5 // consecutive failures before down RecoveryCount = 2 // consecutive successes to return to healthy )
Thresholds for state transitions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContributorHealth ¶
type ContributorHealth struct {
Name string `json:"name"`
State HealthState `json:"state"`
ConsecutiveFails int `json:"consecutive_fails"`
LastSuccess time.Time `json:"last_success"`
LastFailure time.Time `json:"last_failure"`
LastError string `json:"last_error,omitempty"`
StaleSince *time.Time `json:"stale_since,omitempty"` // when we started serving stale data
}
ContributorHealth tracks the health state of a single remote contributor.
type HealthState ¶
type HealthState string
HealthState represents the health state of a remote contributor.
const ( StateHealthy HealthState = "healthy" StateDegraded HealthState = "degraded" StateDown HealthState = "down" )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager tracks health states for remote contributors and manages recovery. It provides a state machine: Healthy → Degraded → Down, with recovery back to Healthy.
func NewManager ¶
NewManager creates a new recovery manager.
func (*Manager) GetAllHealth ¶
func (m *Manager) GetAllHealth() map[string]ContributorHealth
GetAllHealth returns health states for all tracked contributors.
func (*Manager) GetHealth ¶
func (m *Manager) GetHealth(name string) *ContributorHealth
GetHealth returns the health state of a contributor. Returns nil if not tracked.
func (*Manager) IsHealthy ¶
IsHealthy returns true if the contributor is in healthy state (or not tracked).
func (*Manager) RecordFailure ¶
RecordFailure records a failed fetch for a contributor. This may transition the state from Healthy → Degraded → Down.
func (*Manager) RecordSuccess ¶
RecordSuccess records a successful fetch for a contributor. This may transition the state from Degraded/Down back toward Healthy.
func (*Manager) SetOnStateChange ¶
func (m *Manager) SetOnStateChange(fn func(name string, oldState, newState HealthState))
SetOnStateChange sets a callback invoked when a contributor's health state changes.