/
step.ex
93 lines (84 loc) · 2.38 KB
/
step.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
defmodule Ash.Flow.Step do
@moduledoc """
A behaviour for implementing a custom step in a flow.
"""
@callback run(input :: map | nil, opts :: Keyword.t(), context :: map) ::
{:ok, term}
| {:ok, term, %{optional(:notifications) => list(Ash.Notifier.Notification.t())}}
| {:error, term}
@callback describe(opts :: Keyword.t()) :: String.t()
@callback short_name(opts :: Keyword.t()) :: String.t()
@optional_callbacks [describe: 1, short_name: 1]
defmacro __using__(_) do
quote do
@behaviour Ash.Flow.Step
end
end
@doc false
def shared_opts do
[
name: [
type: :atom,
required: true,
doc: "The name of the step. Will be used when expressing dependencies, and step inputs."
],
wait_for: [
type: :any,
doc: """
Ensures that the step happens after the configured step or steps.
This value is just a template that isn't used, except to determine dependencies, so you can
use it like this `wait_for [result(:step_one), result(:step_two)]` or `wait_for result(:step)`.
"""
],
touches_resources: [
type: {:list, :atom},
doc: """
A list of resources touched by any custom logic in this step. This is used in the case that this step is run in a transaction. This is primarily only needed for `custom` steps.
"""
],
description: [
type: :string,
doc: """
A description for the step.
"""
]
]
end
@doc false
def shared_action_opts do
[
resource: [
type: :atom,
required: true,
doc: "The resource to call the action on."
],
action: [
type: :atom,
required: true,
doc: "The action to call on the resource."
],
api: [
type: :atom,
doc:
"The api to use when calling the action. Defaults to the api set in the `flow` section."
],
tenant: [
type: :any,
doc: "A tenant to use for the operation. May be a template or a literal value."
],
input: input()
]
end
@doc false
def input do
[
type: :any,
doc: """
A template for the input.
Available template functions:
- `arg/1` to refer to a flow argument
- `result/1` to refer to the result of another step
"""
]
end
end