Individual (Individual v0.3.3) View Source
Process adapter to handle singleton processes in Elixir applications.
The problem
Sometimes, when yo start your program on cluster with MASTER<->MASTER strategy,
some of your modules should be started only on one nod at a time. The should be
registered within :global
module, but :global
doesn't handle name conflicts
and restarts. This is what Individual
for.
Usage
Wrap your worker or supervisor specification inside any of your supervisors with
Individual
call, passing supervisor specification as argument for Individual
.
Your worker or supervisor should be registered within :global
module.
Examples
# Simple call:
def start(_type, _args) do
Supervisor.start_link([
{Individual, MyModule}
], strategy: :one_for_one, name: Individual.Supervisor)
end
# Call with args:
def start(_type, _args) do
Supervisor.start_link([
{Individual, {MyModule, %{foo: :bar}}}
], strategy: :one_for_one, name: Individual.Supervisor)
end
# To start multiple processes with same name:
def start(_type, _args) do
Supervisor.start_link([
{Individual, Supervisor.child_spec({MyModule, []}, id: Test1)},
{Individual, Supervisor.child_spec({MyModule, []}, id: Test2)}
], strategy: :one_for_one, name: Individual.Supervisor)
end
Link to this section Summary
Functions
This function will start your module, monitored with Individual
. It requires
your module's specification, the same you pass into any of your supervisors.
Link to this section Types
Specs
child_spec() :: :supervisor.child_spec() | {module(), term()} | module()
Link to this section Functions
Specs
start_link(son_childspec :: child_spec()) :: GenServer.on_start()
This function will start your module, monitored with Individual
. It requires
your module's specification, the same you pass into any of your supervisors.
Examples
Individual.start_link(MyModule)
Individual.start_link({MyModule, [1,2,3]})
Individual.start_link(MyModule.child_spec(:foobar))