lifecycle

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package lifecycle implements a job status state machine with validated transitions and optional hooks.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTransition = fmt.Errorf("invalid status transition")

ErrInvalidTransition is returned when a status transition is not allowed.

Functions

func AllowedTransitions

func AllowedTransitions(from types.JobStatus) []types.JobStatus

AllowedTransitions returns the set of statuses a job can move to from its current state.

func CanTransition

func CanTransition(from, to types.JobStatus) bool

CanTransition returns true if the transition from → to is valid.

func Validate

func Validate(from, to types.JobStatus) error

Validate returns an error if the transition from → to is not allowed.

Types

type Hook

type Hook func(jobID string, from, to types.JobStatus)

Hook is called when a job transitions between states.

type Machine

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

Machine enforces valid transitions and fires hooks.

func New

func New() *Machine

New creates a new lifecycle state machine.

func (*Machine) OnTransition

func (m *Machine) OnTransition(h Hook)

OnTransition registers a hook that fires on every valid transition.

func (*Machine) Transition

func (m *Machine) Transition(job *types.Job, to types.JobStatus) error

Transition validates the state change and fires hooks if valid. Returns ErrInvalidTransition if the transition is not allowed.

Jump to

Keyboard shortcuts

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