lifecycle

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lifecycle provides a configurable state machine for AWS resource lifecycle transitions. Resources progress through a sequence of states (e.g., CREATING → AVAILABLE → DELETING → DELETED) either instantly or with configurable delays to simulate real AWS async behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config controls whether lifecycle delays are simulated or instant.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with delays disabled (instant transitions).

func (*Config) EffectiveDelay

func (c *Config) EffectiveDelay(nominal time.Duration) time.Duration

EffectiveDelay returns the actual delay to use for a given nominal delay. Returns 0 if delays are disabled.

func (*Config) Enabled

func (c *Config) Enabled() bool

Enabled returns whether simulated delays are active.

func (*Config) SetEnabled

func (c *Config) SetEnabled(enabled bool)

SetEnabled enables or disables simulated delays globally.

func (*Config) SetSpeedFactor

func (c *Config) SetSpeedFactor(factor float64)

SetSpeedFactor sets a multiplier for all delays (e.g., 0.1 = 10x faster).

type Machine

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

Machine manages the lifecycle of a single resource through a defined set of state transitions.

func NewMachine

func NewMachine(initialState State, transitions []Transition, cfg *Config) *Machine

NewMachine creates a lifecycle machine starting at initialState. transitions maps each state to its next automatic transition.

func (*Machine) ForceState

func (m *Machine) ForceState(s State)

ForceState immediately sets the state, bypassing transitions. Use for external triggers (e.g., user-initiated delete).

func (*Machine) History

func (m *Machine) History() []StateRecord

History returns all state transitions in order.

func (*Machine) OnTransition

func (m *Machine) OnTransition(fn func(from, to State))

OnTransition sets a callback invoked after each automatic transition.

func (*Machine) State

func (m *Machine) State() State

State returns the current state.

func (*Machine) StateTime

func (m *Machine) StateTime() time.Time

StateTime returns when the current state was entered.

func (*Machine) Stop

func (m *Machine) Stop()

Stop cancels any pending automatic transition.

type State

type State string

State represents a resource lifecycle state (e.g., "CREATING", "AVAILABLE").

type StateRecord

type StateRecord struct {
	State     State
	EnteredAt time.Time
}

StateRecord captures a historical state change.

type Transition

type Transition struct {
	From  State
	To    State
	Delay time.Duration // 0 means instant
}

Transition defines a state change with an optional delay.

Jump to

Keyboard shortcuts

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