Packages
journey
0.10.39
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/journey/graph/catalog.ex
defmodule Journey.Graph.Catalog do
@moduledoc false
use Agent
def start_link(_) do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end
def register(%{name: name, version: version} = graph)
when is_binary(name) and is_binary(version) and is_struct(graph, Journey.Graph) do
:ok = Agent.update(__MODULE__, fn state -> state |> Map.put({name, version}, graph) end)
graph
end
def fetch(graph_name, graph_version)
when is_binary(graph_name) and is_binary(graph_version) do
Agent.get(__MODULE__, fn state -> state |> Map.get({graph_name, graph_version}) end)
end
def list(graph_name \\ nil, graph_version \\ nil)
def list(nil, nil) do
Agent.get(__MODULE__, fn state ->
state
|> Map.values()
end)
end
def list(graph_name, nil) when is_binary(graph_name) do
Agent.get(__MODULE__, fn state ->
state
|> Enum.filter(fn {{name, _version}, _graph} -> name == graph_name end)
|> Enum.map(fn {_key, graph} -> graph end)
|> Enum.sort_by(& &1.version, :desc)
end)
end
def list(graph_name, graph_version)
when is_binary(graph_name) and is_binary(graph_version) do
case fetch(graph_name, graph_version) do
nil -> []
graph -> [graph]
end
end
def list(nil, graph_version) when is_binary(graph_version) do
raise ArgumentError, "graph_version cannot be specified without graph_name"
end
def unregister(graph_name, graph_version)
when is_binary(graph_name) and is_binary(graph_version) do
Agent.update(__MODULE__, fn state ->
Map.delete(state, {graph_name, graph_version})
end)
:ok
end
end