This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworkflows.ex
55 lines (45 loc) · 1.72 KB
/
workflows.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
defmodule Workflows do
@external_resource readme = Path.join([__DIR__, "../README.md"])
@moduledoc readme
|> File.read!()
|> String.split("<!-- MDOC -->")
|> Enum.fetch!(1)
alias Workflows.{Activity, Command, Event, Execution, Workflow}
@doc """
Parses a workflow definition.
A workflow is defined by a map-like structure that conforms to the
[Amazon States Language](https://states-language.net/) specification.
## Examples
iex> {:ok, wf} = Workflows.parse(%{
...> "Comment" => "A simple example",
...> "StartAt" => "Hello World",
...> "States" => %{
...> "Hello World" => %{
...> "Type" => "Task",
...> "Resource" => "do-something",
...> "End" => true
...> }
...> }
...> })
iex> wf.start_at
"Hello World"
"""
@spec parse(map()) :: {:ok, Workflow.t()} | {:error, term()}
def parse(definition), do: Workflow.parse(definition)
@doc """
Starts a `workflow` execution with the given `ctx` and `args`.
"""
@spec start(Workflow.t(), Activity.ctx(), Activity.args()) ::
Execution.execution_result() | {:error, term()}
def start(workflow, ctx, args), do: Execution.start(workflow, ctx, args)
@doc """
Resumes an `execution` waiting for `cmd` to continue.
"""
@spec resume(Execution.t(), Command.t()) :: Execution.execution_result() | {:error, term()}
def resume(execution, cmd), do: Execution.resume(execution, cmd)
@doc """
Recovers a `workflow` execution from `events`.
"""
@spec recover(Workflow.t(), list(Event.t())) :: Execution.execution_result() | {:error, term()}
def recover(workflow, events), do: Execution.recover(workflow, events)
end