Documentation
¶
Index ¶
- Constants
- Variables
- type MoveStateMachine
- type ShipmentStateMachine
- type StateMachine
- type StateMachineManager
- func (m *StateMachineManager) CalculateStatuses(ctx context.Context, shp *shipment.Shipment) error
- func (m *StateMachineManager) ForMove(move *shipment.ShipmentMove) StateMachine
- func (m *StateMachineManager) ForShipment(shp *shipment.Shipment) StateMachine
- func (m *StateMachineManager) ForStop(stop *shipment.Stop) StateMachine
- type StateMachineManagerParams
- type StateMachineParams
- type StopStateMachine
- type TransitionError
- type TransitionEvent
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 NewStateMachineManager ¶
func NewStateMachineManager(p StateMachineManagerParams) *StateMachineManager
func (*StateMachineManager) CalculateStatuses ¶
CalculateStatuses calculates and updates the statuses of a shipment and all its related entities
func (*StateMachineManager) ForMove ¶
func (m *StateMachineManager) ForMove(move *shipment.ShipmentMove) StateMachine
func (*StateMachineManager) ForShipment ¶
func (m *StateMachineManager) ForShipment(shp *shipment.Shipment) StateMachine
func (*StateMachineManager) ForStop ¶
func (m *StateMachineManager) ForStop(stop *shipment.Stop) StateMachine
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
Click to show internal directories.
Click to hide internal directories.