
lifecycle
Package lifecycle provides a service manager for registering and running background goroutines with coordinated graceful shutdown.
Index
- type HealthReporter
- type Manager
- func NewManager() *Manager
- func (m *Manager) Health() []WorkerHealth
- func (m *Manager) Names() []string
- func (m *Manager) Register(name string, r Runner)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) SetBackoff(initial, maximum, reset time.Duration)
- func (m *Manager) Stop(timeout time.Duration)
- type Runner
- type Stopper
- type WorkerHealth
type HealthReporter
HealthReporter is the optional interface registered services may implement to expose per-tick health state. Services that satisfy it appear in Manager.Health(); services that do not are silently omitted, so adding the interface is purely additive.
type Manager
Manager registers and supervises background services.
func NewManager
NewManager creates an empty service manager with production backoff defaults.
func (*Manager) Health
Health returns a snapshot of every registered service that implements HealthReporter. Order matches registration order so operators reading the JSON dump see the same service ordering as startup logs.
func (*Manager) Names
Names returns the registered service names in registration order. Intended for tests that assert which services are wired in a given run mode; the supervisor loop itself does not consume this.
func (*Manager) Register
Register adds a named service. Services start in registration order and stop in reverse order.
func (*Manager) Run
Run starts all registered services and blocks until ctx is cancelled. Each service runs in its own goroutine with panic recovery and automatic restart.
func (*Manager) SetBackoff
SetBackoff overrides the supervisor’s restart backoff parameters. Intended for tests that exercise the restart path without paying real wall-clock time. Must be called before Run; values take effect on the next supervise iteration.
func (*Manager) Stop
Stop calls Stop on services that implement Stopper, in reverse registration order. The timeout is divided equally among stoppable services so a slow service cannot starve the rest of their shutdown budget.
type Runner
Runner represents a long-running background task. Run blocks until ctx is cancelled or a fatal error occurs.
type Stopper
Stopper is an optional interface for services that need explicit cleanup beyond context cancellation.
type WorkerHealth
WorkerHealth snapshots a registered service’s last tick outcomes plus its registration name. ConsecutiveFailures resets to 0 on the next success; LastSuccess/LastFailure are zero until the corresponding event happens. Surfaced through Manager.Health() and the admin /api/workers endpoint.
Generated by gomarkdoc