recovery

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewManager(logger forge.Logger) *Manager

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

func (m *Manager) IsHealthy(name string) bool

IsHealthy returns true if the contributor is in healthy state (or not tracked).

func (*Manager) RecordFailure

func (m *Manager) RecordFailure(name string, err error)

RecordFailure records a failed fetch for a contributor. This may transition the state from Healthy → Degraded → Down.

func (*Manager) RecordSuccess

func (m *Manager) RecordSuccess(name string)

RecordSuccess records a successful fetch for a contributor. This may transition the state from Degraded/Down back toward Healthy.

func (*Manager) Remove

func (m *Manager) Remove(name string)

Remove stops tracking a contributor.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL