s3-orchestrator

lifecycle

import "github.com/afreidah/s3-orchestrator/internal/lifecycle"

Package lifecycle provides a service manager for registering and running background goroutines with coordinated graceful shutdown.

Index

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 HealthReporter interface {
    Health() WorkerHealth
}

type Manager

Manager registers and supervises background services.

type Manager struct {
    // contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

NewManager creates an empty service manager with production backoff defaults.

func (*Manager) Health

func (m *Manager) Health() []WorkerHealth

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

func (m *Manager) Names() []string

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

func (m *Manager) Register(name string, r Runner)

Register adds a named service. Services start in registration order and stop in reverse order.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

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

func (m *Manager) SetBackoff(initial, maximum, reset time.Duration)

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

func (m *Manager) Stop(timeout time.Duration)

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 Runner interface {
    Run(ctx context.Context) error
}

type Stopper

Stopper is an optional interface for services that need explicit cleanup beyond context cancellation.

type Stopper interface {
    Stop(ctx context.Context) error
}

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.

type WorkerHealth struct {
    Name                string    `json:"name"`
    LastSuccess         time.Time `json:"last_success,omitempty"`
    LastFailure         time.Time `json:"last_failure,omitempty"`
    LastError           string    `json:"last_error,omitempty"`
    ConsecutiveFailures int       `json:"consecutive_failures"`
}

Generated by gomarkdoc