mirror of
https://github.com/ash-project/ash_state_machine.git
synced 2024-09-21 22:03:12 +12:00
46 lines
824 B
Elixir
46 lines
824 B
Elixir
|
defmodule ThreeStates do
|
||
|
@moduledoc false
|
||
|
use Ash.Resource,
|
||
|
domain: Domain,
|
||
|
data_layer: Ash.DataLayer.Ets,
|
||
|
extensions: [AshStateMachine]
|
||
|
|
||
|
state_machine do
|
||
|
initial_states [:pending]
|
||
|
default_initial_state :pending
|
||
|
|
||
|
transitions do
|
||
|
transition(:begin, from: :pending, to: :executing)
|
||
|
transition(:complete, from: :executing, to: :complete)
|
||
|
transition(:*, from: :*, to: :pending)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
actions do
|
||
|
default_accept :*
|
||
|
defaults [:read, :create]
|
||
|
|
||
|
update :begin do
|
||
|
change transition_state(:executing)
|
||
|
end
|
||
|
|
||
|
update :complete do
|
||
|
change transition_state(:complete)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
ets do
|
||
|
private? true
|
||
|
end
|
||
|
|
||
|
attributes do
|
||
|
uuid_primary_key :id
|
||
|
end
|
||
|
|
||
|
code_interface do
|
||
|
define :create
|
||
|
define :begin
|
||
|
define :complete
|
||
|
end
|
||
|
end
|