Documentation ¶
Overview ¶
Package fsm implements a horizontally scalable finite state machine utilizing MySQL.
Traditional finite state machines manage the states in memory. Package fsm updates and gets the states directly on the MySQL side, so that it avoids the in-memory problem. Thus it is able to be scaled horizontally with no difficulty.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { *DBConfig // Init is the initial state of the finite state machine. Init string // Events is a map from the event name to its transitions. Events map[string]Event }
Config is the configuratoin of the finite state machine.
type DBConfig ¶
type DBConfig struct { // DB represents the connection to the database. DB *sql.DB // Table is the name of the table to be updated. Table string // Field refers to the field in the row to be upated. Field string // Debug deicdes whehter the debugging logs should be shown. Debug bool }
DBConfig is the configuration of the MySQL database.
type Event ¶
type Event struct { // Name is the name of the event. Name string // Src is a slice containing all the possible source states. Src []string // Dst is a destination state that source states transfer to when the event // happens. Dst string }
Event holds the name of an event, with its corresponding state transitions.
type FSM ¶
FSM is a finite state machine storing states in the MySQL database.
func (*FSM) Event ¶
Event updates the state machine according to events defined.
A new record is inserted into the database if the ID doesn't exist. Otherwise the row identified by the ID is updated.
func (*FSM) Initialize ¶
Initialize inserts into the table with the initial state.