View Source Eventize.EventSourcedProcess behaviour (eventize v0.2.0)
EventSourcedProcess is a optininated GenServer
that will
use event sourcing to store its state as a sequence of events.
Instead of using the normal GenServer.handle_call/3
and GenServer.handle_cast/2
callbacks you can now use Eventize.EventSourcedProcess.ProcessBehavior.execute_call/3
and Eventize.EventSourcedProcess.ProcessBehavior.execute_cast/2
.
These function very similar, but instead of modifying the state
you can return a list of events that should be applied. These
events will be stored using the configured event bus and then
applied to the process using the apply_event/2
callback.
All stored events will also be read on startup and the
apply_event/2
functions will be called then as well to
make sure that the state is up to date.
Link to this section Summary
Callbacks
This callback is used to updated the state of the process
after a event has been saved to the Eventize.Persistence.EventStore
.
This callback is used to apply a loaded snapshot to the process.
This callback can be used to specify a list cleanups that should happen after a specific event has been applied to the process.
This callback is used to get metadata for a event before
it's stored in the Eventize.Persistence.EventStore
.
This callback is used to get metadata for a snapshot before
it's stored in the Eventize.Persistence.EventStore
.
This callback can optionally be implimented to return
the stream name that should be used when the events
of this process is stored in the configured
Eventize.Persistence.EventStore
. The default
implimentation will use the last part (seperate on ".")
of the module name lowercased and add the id of the
process.
A callback used when the process is starting up. This should return either a two item tuple where the first item is the initial behavior and the second is the initial state, a single item that is either the initial state, the initial state or nil.
Link to this section Callbacks
@callback apply_event(term(), Eventize.EventSourcedProcess.ApplyEvents.EventContext.t()) :: {term(), atom()} | term()
This callback is used to updated the state of the process
after a event has been saved to the Eventize.Persistence.EventStore
.
You can either return just the new state or a tuple with the new state and a reference to a module that will be the new process behavior for the next incoming message.
This callback is used to apply a loaded snapshot to the process.
This callback can be used to specify a list cleanups that should happen after a specific event has been applied to the process.
This callback is used to get metadata for a event before
it's stored in the Eventize.Persistence.EventStore
.
This callback is used to get metadata for a snapshot before
it's stored in the Eventize.Persistence.EventStore
.
This callback can optionally be implimented to return
the stream name that should be used when the events
of this process is stored in the configured
Eventize.Persistence.EventStore
. The default
implimentation will use the last part (seperate on ".")
of the module name lowercased and add the id of the
process.
A callback used when the process is starting up. This should return either a two item tuple where the first item is the initial behavior and the second is the initial state, a single item that is either the initial state, the initial state or nil.