Packages

Otplabs-lib provides Horde and Mnesia Supervisor, Horde Registry and NodeObserver that loads nodes dynamically when they start. Those recives notitication when a node up and down and update Horde and mnesia cluster.

Current section

Files

Jump to
otplabs lib horde supervisor.ex
Raw

lib/horde/supervisor.ex

defmodule OTPLabs.Horde.Supervisor do
@moduledoc ~S"""
This module is used for initialize nodes dynamically.
"""
use Horde.DynamicSupervisor
require Logger
@doc false
def start_link(_) do
Logger.log(:info, "Starting #{__MODULE__}")
Horde.DynamicSupervisor.start_link(__MODULE__, [strategy: :one_for_one], name: __MODULE__)
end
@impl true
def init(init_arg) do
Logger.log(:info, "init #{__MODULE__} #{inspect(init_arg)}")
[members: members()]
|> Keyword.merge(init_arg)
|> Horde.DynamicSupervisor.init()
end
@doc false
def start_child(child_spec) do
Logger.log(:info, "Starting child #{__MODULE__} #{inspect(child_spec)}")
Horde.DynamicSupervisor.start_child(__MODULE__, child_spec)
end
defp members() do
Enum.map([Node.self() | Node.list()], &{__MODULE__, &1})
end
end