Documentation
¶
Index ¶
Constants ¶
View Source
const ( // Order state machine events OrderEventFailOrder = "fail_order" OrderEventPlaceOrder = "place_order" OrderEventSuccessOrder = "success_order" // Order state machine actions OrderActionBook = "book" OrderActionCallApiV2 = "call_api_v2" OrderActionCheckAvailability = "check_availability" OrderActionFailOrder = "fail_order" OrderActionSendEmail = "send_email" )
Variables ¶
View Source
var ( ErrOrderFsmAction = errors.New("OrderStateMachine action error") ErrOrderFsmBeforeAction = errors.New("OrderStateMachine before action error") // ErrOrderFsmSkip indicates that further processing not need // used in before_actions ErrOrderFsmSkip = errors.New("skip") )
View Source
var OrderTransitions = []OrderTransition{ { From: StateTypeUnknown, To: Created, }, { Event: OrderEventSuccessOrder, From: StateTypeUnknown, To: Finished, }, { Event: OrderEventPlaceOrder, From: Created, To: Started, BeforeActions: []string{ OrderActionCheckAvailability, OrderActionBook, }, }, { Event: OrderEventFailOrder, From: Created, To: Failed, Actions: []string{ OrderActionFailOrder, OrderActionCallApiV2, }, }, { Event: OrderEventSuccessOrder, From: Started, To: Finished, Actions: []string{ OrderActionSendEmail, }, }, }
OrderTransitions generated from transitions.json
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*OrderStateMachine)
func WithActionHandler ¶
func WithActionHandler(h OrderHandleAction) Option
func WithPersister ¶
func WithPersister(p OrderPersistState) Option
func WithTransitions ¶
func WithTransitions(tr []OrderTransition) Option
type OrderHandleAction ¶
type OrderHandleAction func(ctx context.Context, action string, transition OrderTransition, obj *Order) error
OrderHandle handles transitions action
type OrderPersistState ¶
Save state to external storage
type OrderStateMachine ¶
type OrderStateMachine struct {
// contains filtered or unexported fields
}
OrderStateMachine is a FSM that can handle transitions of a lot of objects. eventHandler and transitions are configured before use them.
func NewOrderStateMachine ¶
func NewOrderStateMachine(opts ...Option) *OrderStateMachine
NewOrderStateMachine creates a new state machine.
func (*OrderStateMachine) ChangeState ¶
ChangeState fires a event and if event succeeded then change state.
func (*OrderStateMachine) FindTransitionForStates ¶
func (m *OrderStateMachine) FindTransitionForStates(from, to StateType) (OrderTransition, bool)
Click to show internal directories.
Click to hide internal directories.