Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TransitionState ¶
func TransitionState(ctx context.Context, m *Machine, u StateUpdater, versionID string, from, to model.ObjectState) error
TransitionState validates a state change via the FSM, then atomically updates the database. This is the single entry point for all object state changes, providing dual protection:
- FSM validation (catches programming errors early)
- DB compare-and-set (prevents races at the data level)
When transitioning to ObjectStateFailed, use TransitionToFailed instead to record the phase that failed and the error message.
func TransitionToFailed ¶
func TransitionToFailed(ctx context.Context, m *Machine, u StateUpdater, versionID string, from model.ObjectState, lastError string) error
TransitionToFailed validates the transition to ObjectStateFailed via the FSM, then atomically updates the database, recording the source state (FailedAtState) and the error message. Workers use FailedAtState to determine the correct retry target.
Types ¶
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine is a generic, extensible finite state machine. States and transitions can be registered dynamically, supporting future additions without modifying existing logic.
func NewObjectStateMachine ¶
func NewObjectStateMachine() *Machine
NewObjectStateMachine returns a state machine pre-configured with the standard object lifecycle transitions.
func (*Machine) CanTransition ¶
CanTransition reports whether moving from → to is allowed.
func (*Machine) NextStates ¶
NextStates returns all states reachable from the given state.
func (*Machine) Register ¶
func (m *Machine) Register(transitions ...Transition)
Register adds one or more valid transitions.
type StateUpdater ¶
type StateUpdater interface {
UpdateVersionState(ctx context.Context, versionID string, from, to model.ObjectState) error
UpdateVersionStateToFailed(ctx context.Context, versionID string, from model.ObjectState, lastError string) error
}
StateUpdater abstracts the DB compare-and-set for state transitions.
type Transition ¶
Transition defines a valid state change.