Packages
journey
0.10.37
0.10.58
0.10.57
0.10.56
0.10.55
0.10.54
0.10.53
0.10.52
0.10.51
0.10.50
0.10.49
0.10.48
0.10.47
0.10.46
0.10.45
0.10.44
0.10.43
0.10.41
0.10.40
0.10.39
0.10.38
0.10.37
0.10.36
0.10.35
0.10.34
0.10.33
0.10.32
0.10.31
0.10.30
0.10.29
0.10.28
0.10.27
0.10.26
0.10.25
0.10.24
0.10.23
0.10.22
0.0.9
retired
0.0.8
0.0.7
0.0.6
0.0.5
0.0.3
0.0.2
Journey is a library for defining and running durable workflows with persistence, reliability, and scalability.
Current section
Files
Jump to
Current section
Files
lib/examples/useless_machine.ex
defmodule UselessMachine do
import Journey.Node
@moduledoc """
This module ([lib/examples/useless_machines.ex](https://github.com/markmark206/journey/blob/main/lib/examples/useless_machine.ex)) contains an example of building a Useless Machine using Journey.
Here is an example of running the useless Machine:
```elixir
iex> graph = UselessMachine.graph()
iex> execution = Journey.start_execution(graph)
iex> Journey.get_value(execution, :switch)
{:error, :not_set}
iex> Journey.get_value(execution, :paw)
{:error, :not_set}
iex> Journey.set(execution, :switch, "on")
iex> # updating switch triggers :paw
iex> {:ok, "updated :switch"} = Journey.get_value(execution, :paw, wait: :any)
iex> # :paw set switch back to "off"
iex> {:ok, "off"} = Journey.get_value(execution, :switch, wait: :any)
```
"""
@doc """
This function defines the graph for the Useless Machine.
It starts with a switch input and mutates the state to "off" when the switch
is toggled, simulating the behavior of a Useless Machine.
"""
def graph() do
Journey.new_graph(
"useless machine example graph",
"v1.0.0",
[
input(:switch),
mutate(:paw, [:switch], &lol_no/1, mutates: :switch)
]
)
end
@doc """
This function simulates the paw's response when the switch is toggled.
It prints a message and mutates the state of the :switch node to "off".
"""
def lol_no(%{switch: switch}) do
IO.puts("paw says: '#{switch}? lol no'")
{:ok, "off"}
end
end