schedulerrecovery

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	ID        string
	StartedAt time.Time
	Stuck     []string
}

func NewAttempt

func NewAttempt(observedAt time.Time, stuck []string) Attempt

type AttemptStore

type AttemptStore interface {
	Begin(context.Context, Attempt) (bool, error)
	Finish(context.Context, Result) error
}

type CommandConfig

type CommandConfig struct {
	Checkpoint []string
	Restart    []string
	Progress   []string
	Timeout    time.Duration
}

type CommandExecutor

type CommandExecutor struct {
	Config CommandConfig
}

func (CommandExecutor) AwaitProgress

func (executor CommandExecutor) AwaitProgress(ctx context.Context, attempt Attempt) ([]string, []string, error)

func (CommandExecutor) Checkpoint

func (executor CommandExecutor) Checkpoint(ctx context.Context, attempt Attempt) (string, error)

func (CommandExecutor) RestartDispatcher

func (executor CommandExecutor) RestartDispatcher(ctx context.Context, attempt Attempt) error

func (CommandExecutor) Validate

func (executor CommandExecutor) Validate() error

type CommandObserver

type CommandObserver struct {
	Argv    []string
	Timeout time.Duration
}

func (CommandObserver) Observe

func (observer CommandObserver) Observe(ctx context.Context) (Observation, error)

func (CommandObserver) Validate

func (observer CommandObserver) Validate() error

type Controller

type Controller struct {
	Policy    Policy
	Observer  Observer
	Heartbeat HeartbeatReader
	Attempts  AttemptStore
	Executor  Executor
	Events    EventSink
	Now       func() time.Time
}

func (Controller) Tick

func (controller Controller) Tick(ctx context.Context) (Decision, Result, error)

type Decision

type Decision struct {
	Recover bool
	Reason  string
	Stuck   []string
}

func Evaluate

func Evaluate(policy Policy, observation Observation) Decision

type Event

type Event struct {
	At        time.Time `json:"at"`
	State     string    `json:"state"`
	Reason    string    `json:"reason"`
	AttemptID string    `json:"attempt_id,omitempty"`
	Stuck     []string  `json:"stuck,omitempty"`
	Error     string    `json:"error,omitempty"`
}

type EventSink

type EventSink interface {
	Emit(context.Context, Event) error
}

type Executor

type Executor interface {
	Checkpoint(context.Context, Attempt) (string, error)
	RestartDispatcher(context.Context, Attempt) error
	AwaitProgress(context.Context, Attempt) (progressed, remaining []string, err error)
}

type FileStore

type FileStore struct {
	Path     string
	LockPath string
}

func (FileStore) Begin

func (store FileStore) Begin(_ context.Context, attempt Attempt) (bool, error)

func (FileStore) Finish

func (store FileStore) Finish(_ context.Context, result Result) error

func (FileStore) ReadHeartbeat

func (store FileStore) ReadHeartbeat(_ context.Context) (Heartbeat, error)

func (FileStore) RecordHeartbeat

func (store FileStore) RecordHeartbeat(_ context.Context, heartbeat Heartbeat) error

type Heartbeat

type Heartbeat struct {
	At       time.Time `json:"at"`
	Progress string    `json:"progress"`
}

type HeartbeatReader

type HeartbeatReader interface {
	ReadHeartbeat(context.Context) (Heartbeat, error)
}

type MetricsFileSink

type MetricsFileSink struct{ Path string }

func (MetricsFileSink) Emit

func (sink MetricsFileSink) Emit(_ context.Context, event Event) error

type MultiSink

type MultiSink []EventSink

func (MultiSink) Emit

func (sinks MultiSink) Emit(ctx context.Context, event Event) error

type Observation

type Observation struct {
	ObservedAt      time.Time
	ActiveIntents   int
	PendingCreates  []PendingCreate
	ManagerUptime   time.Duration
	LastRecoveryAt  time.Time
	HeartbeatAt     time.Time
	RecoveryRunning bool
}

type Observer

type Observer interface {
	Observe(context.Context) (Observation, error)
}

type PendingCreate

type PendingCreate struct {
	ID            string        `json:"id"`
	Age           time.Duration `json:"age_nanoseconds"`
	CreateAttempt int           `json:"create_attempt"`
}

type Policy

type Policy struct {
	MinimumStuckAge time.Duration
	MinimumUptime   time.Duration
	Cooldown        time.Duration
	HeartbeatStale  time.Duration
}

type Result

type Result struct {
	AttemptID  string
	Suppressed bool
	Checkpoint string
	Progressed []string
	Remaining  []string
	Recovered  bool
	FinishedAt time.Time
	Error      string
}

func Recover

func Recover(ctx context.Context, observedAt time.Time, decision Decision, store AttemptStore, executor Executor, now func() time.Time) (Result, error)

Jump to

Keyboard shortcuts

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