statemachine

package
v0.0.0-...-20e6d49 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// * Stop Events
	EventStopArrived  = TransitionEvent("StopArrived")
	EventStopDeparted = TransitionEvent("StopDeparted")
	EventStopCanceled = TransitionEvent("StopCanceled")

	// * Move Events
	EventMoveAssigned  = TransitionEvent("MoveAssigned")
	EventMoveStarted   = TransitionEvent("MoveStarted")
	EventMoveCompleted = TransitionEvent("MoveCompleted")
	EventMoveCanceled  = TransitionEvent("MoveCanceled")

	// * Shipment Events
	EventShipmentAssigned          = TransitionEvent("ShipmentAssigned")
	EventShipmentPartiallyAssigned = TransitionEvent("ShipmentPartiallyAssigned")
	EventShipmentInTransit         = TransitionEvent("ShipmentInTransit")
	EventShipmentCompleted         = TransitionEvent("ShipmentCompleted")
	EventShipmentCanceled          = TransitionEvent("ShipmentCanceled")
	EventShipmentDelayed           = TransitionEvent("ShipmentDelayed")
	EventShipmentPartialCompleted  = TransitionEvent("ShipmentPartialCompleted")
	EventShipmentMarkedForBilling  = TransitionEvent("ShipmentMarkedForBilling")
)

Variables

View Source
var Module = fx.Module("statemachine", fx.Provide(
	NewStateMachineManager,
))

Functions

This section is empty.

Types

type MoveStateMachine

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

func (*MoveStateMachine) CanTransition

func (sm *MoveStateMachine) CanTransition(ctx context.Context, event TransitionEvent) bool

func (*MoveStateMachine) CurrentState

func (sm *MoveStateMachine) CurrentState() string

func (*MoveStateMachine) IsInTerminalState

func (sm *MoveStateMachine) IsInTerminalState() bool

IsInTerminalState checks if the current state is terminal

func (*MoveStateMachine) Transition

func (sm *MoveStateMachine) Transition(ctx context.Context, event TransitionEvent) error

type ShipmentStateMachine

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

func (*ShipmentStateMachine) CanTransition

func (sm *ShipmentStateMachine) CanTransition(ctx context.Context, event TransitionEvent) bool

func (*ShipmentStateMachine) CurrentState

func (sm *ShipmentStateMachine) CurrentState() string

func (*ShipmentStateMachine) IsInTerminalState

func (sm *ShipmentStateMachine) IsInTerminalState() bool

func (*ShipmentStateMachine) Transition

func (sm *ShipmentStateMachine) Transition(ctx context.Context, event TransitionEvent) error

type StateMachine

type StateMachine interface {
	// CurrentState returns the current state of the entity
	CurrentState() string

	// CanTransition checks if a transition is possible given an event
	CanTransition(ctx context.Context, event TransitionEvent) bool

	// Transition attempts to transition to a new state based on an event
	Transition(ctx context.Context, event TransitionEvent) error

	// IsInTerminalState returns true if current is terminal
	IsInTerminalState() bool
}

func NewMoveStateMachine

func NewMoveStateMachine(move *shipment.ShipmentMove) StateMachine

func NewShipmentStateMachine

func NewShipmentStateMachine(shp *shipment.Shipment) StateMachine

func NewStopStateMachine

func NewStopStateMachine(stop *shipment.Stop) StateMachine

type StateMachineManager

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

func (*StateMachineManager) CalculateStatuses

func (m *StateMachineManager) CalculateStatuses(ctx context.Context, shp *shipment.Shipment) error

CalculateStatuses calculates and updates the statuses of a shipment and all its related entities

func (*StateMachineManager) ForMove

func (*StateMachineManager) ForShipment

func (m *StateMachineManager) ForShipment(shp *shipment.Shipment) StateMachine

func (*StateMachineManager) ForStop

func (m *StateMachineManager) ForStop(stop *shipment.Stop) StateMachine

type StateMachineManagerParams

type StateMachineManagerParams struct {
	fx.In

	Logger *logger.Logger
}

type StateMachineParams

type StateMachineParams struct {
	fx.In

	Logger *logger.Logger
}

type StopStateMachine

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

func (*StopStateMachine) CanTransition

func (sm *StopStateMachine) CanTransition(ctx context.Context, event TransitionEvent) bool

func (*StopStateMachine) CurrentState

func (sm *StopStateMachine) CurrentState() string

func (*StopStateMachine) IsInTerminalState

func (sm *StopStateMachine) IsInTerminalState() bool

func (*StopStateMachine) Transition

func (sm *StopStateMachine) Transition(ctx context.Context, event TransitionEvent) error

type TransitionError

type TransitionError struct {
	CurrentState string `json:"currentState"`
	TargetState  string `json:"targetState"`
	Event        TransitionEvent
	Message      string `json:"message"`
}

func (*TransitionError) Error

func (e *TransitionError) Error() string

type TransitionEvent

type TransitionEvent string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳