Reactor.Process
A Reactor extension that provides steps for working with supervisors and processes.
Example
The following example uses Reactor to start a supervisor and add children to it.
MyApp.RepoSupervisor is a module-based Supervisor with no children of its
own. Each start_link and start_child step returns a result struct. Read the
supervisor pid with result(:supervisor, [:pid]).
defmodule StartAllReposReactor do
use Reactor, extensions: [Reactor.Process]
start_link :supervisor do
child_spec {MyApp.RepoSupervisor, []}
end
step :all_repos do
run fn _ ->
Application.get_env(:my_app, :ecto_repos)
end
end
map :migrate_all_repos do
source result(:all_repos)
step :migrate do
argument :repo, element(:migrate_all_repos)
run &migrate_repo/2
end
start_child :start_child do
supervisor result(:supervisor, [:pid])
child_spec element(:migrate_all_repos)
end
end
return :supervisor
defp migrate_repo(args, _context) do
Ecto.Migrator.with_repo(args.repo, fn repo ->
with :ok <- repo_create(repo) do
Ecto.Migrator.run(repo, :up, all: true)
{:ok, repo}
end
end)
end
defp repo_create(repo) do
case repo.__adapter__().storage_up(repo.config()) do
:ok -> :ok
{:error, :already_up} -> :ok
{:error, reason} -> {:error, reason}
end
end
end
%Reactor.Process.Step.StartLink.Result{pid: supervisor} = Reactor.run!(StartAllReposReactor)
Installation
If available in Hex, the package can be installed
by adding reactor_process to your list of dependencies in mix.exs:
def deps do
[
{:reactor_process, "~> 0.18.0"}
]
end
Documentation for the latest release is available on HexDocs.
Licence
This software is licensed under the terms of the MIT License.
See the LICENSE file included with this package for the terms.