Reactor.Process
View SourceAn extensions which provides steps for working with supervisors.
reactor.count_children
count_children name
Returns information about a Supervisor's children.
See the documentation for Supervisor.count_children/1
for more information.
Nested DSLs
Examples
start_link :supervisor do
child_spec value({Supervisor, strategy: :one_for_one}
end
count_children :children do
supervisor result(:supervisor)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
supervisor | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom} | The supervisor to query | |
description | String.t | An optional description for the step | |
module | module | Supervisor | The module to use. Must export count_children/1 |
reactor.count_children.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.count_children.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.count_children.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.CountChildren
reactor.delete_child
delete_child name
Deletes a child specification by id from a Supervisor.
See the documentation for Supervisor.delete_child/2
for more information.
Nested DSLs
Examples
delete_child :delete_child do
supervisor input(:supervisor)
child_id input(:child_id)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
supervisor | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom} | The supervisor to query | |
child_id | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | The ID for the child spec to remove | |
description | String.t | An optional description for the step | |
module | module | Supervisor | The module to use. Must export count_children/1 |
reactor.delete_child.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.delete_child.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.delete_child.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.DeleteChild
reactor.process_exit
process_exit name
Send an exit signal with the given reason
to process
.
See the documentation for Process.exit/2
for more information.
Nested DSLs
Examples
process_exit :exit do
process result(:server)
reason value(:kill)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
process | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | The process to terminate | |
reason | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | The termination reason | |
description | String.t | An optional description for the step | |
timeout | timeout | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | 5000 | How long to wait for the process to terminate before timing out |
wait_for_exit? | boolean | false | Whether to wait until the process exits before continuing |
reactor.process_exit.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.process_exit.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.process_exit.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.ProcessExit
reactor.restart_child
restart_child name
Restarts a child process identified by child_id.
See Supervisor.restart_child/2
for more information.
Nested DSLs
Examples
restart_child :restart_child do
supervisor input(:supervisor)
child_id input(:child_id)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
supervisor | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom} | The supervisor to query | |
child_id | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | The ID for the child spec to restart | |
description | String.t | An optional description for the step | |
module | module | Supervisor | The module to use. Must export restart_child/2 |
reactor.restart_child.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.restart_child.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.restart_child.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.RestartChild
reactor.start_child
start_child name
Adds a child specification to a supervisor and starts that child.
See the documentation for Supervisor.start_child/2
for more information.
Nested DSLs
Examples
start_link :supervisor do
child_spec value({Supervisor, strategy: :one_for_one}
end
start_child :worker do
supervisor result(:supervisor)
child_spec value({Agent, initial_value: 0})
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
supervisor | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom} | The supervisor to query | |
description | String.t | An optional description for the step | |
module | module | Supervisor | The module to use. Must export start_child/2 |
fail_on_already_present? | boolean | true | Whether the step should fail if the child spec is already present in the supervisor |
fail_on_already_started? | boolean | true | Whether the step should fail if the start function returns an already started error |
terminate_on_undo? | boolean | true | Whether to terminate the started process when the Reactor is undoing changes |
termination_reason | any | :kill | The reason to give to the process when terminating it |
termination_timeout | timeout | 5000 | How long to wait for a process to terminate |
reactor.start_child.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.start_child.child_spec
child_spec source
Specifies a child spec as used by a supervisor.
Examples
child_spec {Supervisor, name: __MODULE__.Supervisor}
child_spec input(:initial_value) do
transform fn initial_value ->
fn -> initial_value end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
source | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | {module, keyword} | module | The child spec |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description for the child spec | |
transform | (any -> any) | module | nil | An optional transformation function which can be used to modify the child spec before it is passed to the step. |
Introspection
Target: Reactor.Process.Dsl.ChildSpec
reactor.start_child.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.start_child.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.StartChild
reactor.start_link
start_link name
Starts a process which is linked to the process running the Reactor.
See the documentation for Reactor.Process.Step.StartLink
for more information.
Nested DSLs
Examples
start_link :supervisor do
child_spec {Supervisor, name: __MODULE__.Supervisor})
end
input :initial_value
start_link :agent do
child_spec result(:value), transform: &{Agent, fn -> &1 end}
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description for the step | |
fail_on_already_started? | boolean | true | Whether the step should fail if the start function returns an already started error |
fail_on_ignore? | boolean | true | Whether the step should fail if the start function returns :ignore |
terminate_on_undo? | boolean | true | Whether to terminate the started process when the Reactor is undoing changes |
termination_reason | any | :kill | The reason to give to the process when terminating it |
termination_timeout | timeout | 5000 | How long to wait for a process to terminate |
reactor.start_link.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.start_link.child_spec
child_spec source
Specifies a child spec as used by a supervisor.
Examples
child_spec {Supervisor, name: __MODULE__.Supervisor}
child_spec input(:initial_value) do
transform fn initial_value ->
fn -> initial_value end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
source | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | {module, keyword} | module | The child spec |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description for the child spec | |
transform | (any -> any) | module | nil | An optional transformation function which can be used to modify the child spec before it is passed to the step. |
Introspection
Target: Reactor.Process.Dsl.ChildSpec
reactor.start_link.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.start_link.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where
Introspection
Target: Reactor.Process.Dsl.StartLink
reactor.terminate_child
terminate_child name
Terminates the given child identified by child_id
.
See the documentation for Supervisor.terminate_child/2
for more information.
Restarting
When the reactor is undoing changes, it is possible for this step to restart
the terminated child using restart_child/2
. Be aware that this will only
work if the child spec hasn't subsequently been deleted by another step and
the restart_child/2
function is present on the module (ie not
DynamicSupervisor
).
Child ID
The child_id
argument can take either a traditional child ID (for a
traditional Supervisor
) or a PID (for a DynamicSupervisor
). It's up to
you to make sure you provide the correct inputs.
Nested DSLs
Examples
terminate_child :terminate_child do
supervisor input(:supervisor)
child_id input(:child_id)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
name | atom | A unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps |
Options
Name | Type | Default | Docs |
---|---|---|---|
supervisor | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom} | The supervisor to query | |
child_id | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | The ID for the child spec to remove | |
description | String.t | An optional description for the step | |
module | module | Supervisor | The module to use. Must export start_child/2 |
fail_on_not_found? | boolean | true | Whether the step should fail if the no child is found under the child_id |
restart_on_undo? | boolean | false | Whether to terminate the started process when the Reactor is undoing changes |
reactor.terminate_child.wait_for
wait_for names
Wait for the named step to complete before allowing this one to start.
Desugars to argument :_, result(step_to_wait_for)
Examples
wait_for :create_user
Arguments
Name | Type | Default | Docs |
---|---|---|---|
names | atom | list(atom) | The name of the step to wait for. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description. |
Introspection
Target: Reactor.Dsl.WaitFor
reactor.terminate_child.guard
guard fun
Provides a flexible method for conditionally executing a step, or replacing it's result.
Expects a two arity function which takes the step's arguments and context and returns one of the following:
:cont
- the guard has passed.{:halt, result}
- the guard has failed - instead of executing the step use the provided result.
Examples
step :read_file_via_cache do
argument :path, input(:path)
run &File.read(&1.path)
guard fn %{path: path}, %{cache: cache} ->
case Cache.get(cache, path) do
{:ok, content} -> {:halt, {:ok, content}}
_ -> :cont
end
end
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
fun | (any, any -> any) | mfa | The guard function. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Guard
reactor.terminate_child.where
where predicate
Only execute the surrounding step if the predicate function returns true.
This is a simple version of guard
which provides more flexibility at the cost of complexity.
Examples
step :read_file do
argument :path, input(:path)
run &File.read(&1.path)
where &File.exists?(&1.path)
end
Arguments
Name | Type | Default | Docs |
---|---|---|---|
predicate | (any -> any) | mfa | (any, any -> any) | mfa | Provide a function which takes the step arguments and optionally the context and returns a boolean value. |
Options
Name | Type | Default | Docs |
---|---|---|---|
description | String.t | An optional description of the guard. |
Introspection
Target: Reactor.Dsl.Where