lifecycle

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidTransition

func IsValidTransition(from, to PluginPhase) bool

IsValidTransition checks if moving from 'from' to 'to' is allowed.

Types

type Observer

type Observer func(pluginID string, t Transition)

Observer is called on every state transition.

type PluginPhase

type PluginPhase string

PluginPhase represents the current lifecycle state of a plugin.

const (
	PhaseUninstalled  PluginPhase = "Uninstalled"
	PhaseInstalling   PluginPhase = "Installing"
	PhaseInstalled    PluginPhase = "Installed"
	PhaseBuilding     PluginPhase = "Building"    // dev only: initial go build
	PhaseBuildFailed  PluginPhase = "BuildFailed" // dev only: build error
	PhaseValidating   PluginPhase = "Validating"
	PhaseStarting     PluginPhase = "Starting"
	PhaseRunning      PluginPhase = "Running"
	PhaseDegraded     PluginPhase = "Degraded"
	PhaseRecovering   PluginPhase = "Recovering"
	PhaseStopping     PluginPhase = "Stopping"
	PhaseStopped      PluginPhase = "Stopped"
	PhaseFailed       PluginPhase = "Failed"
	PhaseUninstalling PluginPhase = "Uninstalling"
)

func (PluginPhase) IsActive

func (p PluginPhase) IsActive() bool

IsActive returns true if the plugin process should be running.

func (PluginPhase) IsTerminal

func (p PluginPhase) IsTerminal() bool

IsTerminal returns true if the phase is a terminal resting state.

type PluginStateMachine

type PluginStateMachine struct {
	Retry RetryState
	// contains filtered or unexported fields
}

PluginStateMachine manages the lifecycle phase for a single plugin. It is thread-safe and notifies observers on every transition.

func NewPluginStateMachine

func NewPluginStateMachine(pluginID string, initial PluginPhase) *PluginStateMachine

NewPluginStateMachine creates a state machine starting at the given phase.

func (*PluginStateMachine) AddObserver

func (sm *PluginStateMachine) AddObserver(obs Observer)

AddObserver registers a callback for state transitions.

func (*PluginStateMachine) ForcePhase

func (sm *PluginStateMachine) ForcePhase(phase PluginPhase, reason string)

ForcePhase sets the phase without validation. Use only during reconciliation or initial load from persisted state.

func (*PluginStateMachine) History

func (sm *PluginStateMachine) History() []Transition

History returns a copy of the transition history.

func (*PluginStateMachine) Phase

func (sm *PluginStateMachine) Phase() PluginPhase

Phase returns the current phase (thread-safe).

func (*PluginStateMachine) TransitionTo

func (sm *PluginStateMachine) TransitionTo(next PluginPhase, reason string) error

TransitionTo attempts a state transition. Returns an error if the transition is not valid.

type RetryState

type RetryState struct {
	Attempts    int
	NextBackoff time.Duration
	LastAttempt time.Time
}

RetryState tracks exponential backoff for crash recovery.

func (*RetryState) Advance

func (r *RetryState) Advance()

Advance increments the retry counter and doubles the backoff (capped).

func (*RetryState) CanRetry

func (r *RetryState) CanRetry() bool

CanRetry returns true if we haven't exhausted retries.

func (*RetryState) Reset

func (r *RetryState) Reset()

Reset clears retry state after a successful recovery.

type Transition

type Transition struct {
	From      PluginPhase `json:"from"`
	To        PluginPhase `json:"to"`
	Reason    string      `json:"reason"`
	Timestamp time.Time   `json:"timestamp"`
}

Transition records a state change for audit/debugging.

Jump to

Keyboard shortcuts

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