booter v0.3.0 Booter
Booter allows modules to define a list of boot steps using module attributes. Each step define what to call, what it requires and enables. A directed acyclic graph is then created from theses steps and progressively executed.
Why? Complicated applications can be composed of multiple subsystems or groups or processes, independants or dependants of
each others. And starting theses subsystems is not easy as :application.start/2
or a supervisor child spec.
Inspired/adapted to Elixir by RabbitMQ's boot process implemented in rabbit.erl and rabbit_misc.erl. For an in-depth explaination, read Alvaro Videla's article and slides.
Usage
Defining boot steps
Using boot_step/3
macro (recommended):
defmodule MyModule do
use Booter
# without name (__MODULE__ is assumed)
boot_step mfa: {mod, fun, args}, requires: :required_step, enables: :another_step
# with name
boot_step :awesome_name, mfa: {mod, fun, args}, requires: :required_step, enables: :another_step
# With name and description
boot_step :awesome_name, "Unicorn generator", mfa: {mod,fun,args}, requires: :rainbow_server, enables: :magic
end
Or without:
defmodule MyModule do
Module.register_attribute __MODULE__, :boot_step, accumulate: true, persist: true
@boot_step %Booter.Step{name: :awesome_step, description: "Awesome things",
mfa: { :application, :start, [:awesome] },
requires: awesome_step}
end
Start boot
Just call Booter.boot!
. Can raise exceptions.
Usually called in start/2
of Application behaviour.
defmodule MyApp do
use Application
def start(_) do
# Start your main supervisor
{ :ok, pid } = Supervisor.start_link()
# Boot the rest
Booter.boot!
{ :ok, pid }
end
end
Link to this section Summary
Functions
Boot the steps
Macro to define a boot_step
List steps of the given module
List steps of the given list of modules
List steps of the given modules
and order them using ordered_steps/1
Orders a list of boot steps
Link to this section Functions
boot!(modules \\ nil)
boot!([module(), ...] | nil) :: [ {:ok | :skip | :no_mfa | :error, Booter.Step.t(), any()}, ... ]
Boot the steps
Macro to define a boot_step
List steps of the given module
modules_steps(modules \\ nil)
modules_steps([module(), ...] | nil) :: [Booter.Step.t(), ...]
List steps of the given list of modules
ordered_modules_steps(modules \\ nil)
ordered_modules_steps([module(), ...] | nil) :: [Booter.Step.t(), ...]
List steps of the given modules
and order them using ordered_steps/1
ordered_steps(unordered_steps)
ordered_steps([Booter.Step.t(), ...]) :: [Booter.Step.t(), ...]
Orders a list of boot steps