Reactor.Process

View Source

An 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
supervisorReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom}The supervisor to query
descriptionString.tAn optional description for the step
modulemoduleSupervisorThe 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
supervisorReactor.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_idReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.ValueThe ID for the child spec to remove
descriptionString.tAn optional description for the step
modulemoduleSupervisorThe 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
processReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.ValueThe process to terminate
reasonReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.ValueThe termination reason
descriptionString.tAn optional description for the step
timeouttimeout | Reactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value5000How long to wait for the process to terminate before timing out
wait_for_exit?booleanfalseWhether 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
supervisorReactor.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_idReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.ValueThe ID for the child spec to restart
descriptionString.tAn optional description for the step
modulemoduleSupervisorThe 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
supervisorReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | pid | atom | {:global, any} | {:via, module, any} | {atom, atom}The supervisor to query
descriptionString.tAn optional description for the step
modulemoduleSupervisorThe module to use. Must export start_child/2
fail_on_already_present?booleantrueWhether the step should fail if the child spec is already present in the supervisor
fail_on_already_started?booleantrueWhether the step should fail if the start function returns an already started error
terminate_on_undo?booleantrueWhether to terminate the started process when the Reactor is undoing changes
termination_reasonany:killThe reason to give to the process when terminating it
termination_timeouttimeout5000How 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
sourceReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | {module, keyword} | moduleThe child spec

Options

NameTypeDefaultDocs
descriptionString.tAn optional description for the child spec
transform(any -> any) | module | nilAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn optional description of the guard.

Introspection

Target: Reactor.Dsl.Where

Introspection

Target: Reactor.Process.Dsl.StartChild

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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
descriptionString.tAn optional description for the step
fail_on_already_started?booleantrueWhether the step should fail if the start function returns an already started error
fail_on_ignore?booleantrueWhether the step should fail if the start function returns :ignore
terminate_on_undo?booleantrueWhether to terminate the started process when the Reactor is undoing changes
termination_reasonany:killThe reason to give to the process when terminating it
termination_timeouttimeout5000How long to wait for a process to terminate
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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn optional description.

Introspection

Target: Reactor.Dsl.WaitFor

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

NameTypeDefaultDocs
sourceReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.Value | {module, keyword} | moduleThe child spec

Options

NameTypeDefaultDocs
descriptionString.tAn optional description for the child spec
transform(any -> any) | module | nilAn 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

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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn optional description of the guard.

Introspection

Target: Reactor.Dsl.Guard

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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
nameatomA unique name for the step. Used when choosing the return value of the Reactor and for arguments into other steps

Options

NameTypeDefaultDocs
supervisorReactor.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_idReactor.Template.Element | Reactor.Template.Input | Reactor.Template.Result | Reactor.Template.ValueThe ID for the child spec to remove
descriptionString.tAn optional description for the step
modulemoduleSupervisorThe module to use. Must export start_child/2
fail_on_not_found?booleantrueWhether the step should fail if the no child is found under the child_id
restart_on_undo?booleanfalseWhether 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

NameTypeDefaultDocs
namesatom | list(atom)The name of the step to wait for.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
fun(any, any -> any) | mfaThe guard function.

Options

NameTypeDefaultDocs
descriptionString.tAn 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

NameTypeDefaultDocs
predicate(any -> any) | mfa | (any, any -> any) | mfaProvide a function which takes the step arguments and optionally the context and returns a boolean value.

Options

NameTypeDefaultDocs
descriptionString.tAn optional description of the guard.

Introspection

Target: Reactor.Dsl.Where

Introspection

Target: Reactor.Process.Dsl.TerminateChild