Built-in in-memory Finitomata.Persistency adapter backed by a named ETS table.
It stores one {state, payload} snapshot per FSM (keyed by the FSM name) and reloads
it when an FSM with the same name starts again. Because the table is owned by a
long-lived process rather than by the FSM itself, snapshots survive the transient
restart of an individual FSM (for example after a crash), which makes this adapter a
zero-boilerplate fit for development, tests, and single-node deployments that only
need durability for the lifetime of the node.
In-memory only
Snapshots are kept in ETS and are lost when the node stops. Use
Finitomata.Persistency.DETS for durability across node restarts, or a custom
Finitomata.Persistency implementation (for example via
Finitomata.Persistency.Persistable) to target an external database.
Usage
Add the table owner to your supervision tree and point use Finitomata at this module:
children = [
Finitomata.Persistency.ETS,
{Finitomata.Supervisor, id: MyApp.Fsm}
]
defmodule MyApp.Order do
use Finitomata, fsm: @fsm, persistency: Finitomata.Persistency.ETS
endStart FSMs whose name equals the entity id so that the store and load keys line up:
Finitomata.start_fsm(MyApp.Fsm, MyApp.Order, order_id, %MyApp.Order{id: order_id})Configuration
The ETS table name defaults to Finitomata.Persistency.ETS and can be overridden:
config :finitomata, Finitomata.Persistency.ETS, table: :my_fsm_snapshots
Summary
Functions
Reads the snapshot stored for name, or nil
Reads the last persisted failure for name, or nil
Removes the snapshot and the last error stored for name
Starts the process owning the snapshot table; add it to your supervision tree
The ETS table name in use (configurable via config :finitomata, Finitomata.Persistency.ETS)
Functions
@spec get(Finitomata.fsm_name()) :: Finitomata.Persistency.snapshot() | nil
Reads the snapshot stored for name, or nil
@spec last_error(Finitomata.fsm_name()) :: Finitomata.Persistency.error() | nil
Reads the last persisted failure for name, or nil
@spec purge(Finitomata.fsm_name()) :: :ok
Removes the snapshot and the last error stored for name
@spec start_link(keyword()) :: GenServer.on_start()
Starts the process owning the snapshot table; add it to your supervision tree
@spec table() :: atom()
The ETS table name in use (configurable via config :finitomata, Finitomata.Persistency.ETS)