ha-handler/lib/ha_handler/pgsql/supervisor.ex

24 lines
506 B
Elixir
Raw Permalink Normal View History

2022-02-19 10:18:05 +01:00
defmodule HAHandler.PGSQL.Supervisor do
use Supervisor
2022-02-19 10:18:05 +01:00
alias HAHandler.PGSQL.Watcher, as: PGSQLWatcher
2022-02-19 10:18:05 +01:00
def start_link(opts) do
Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
end
2022-02-19 10:18:05 +01:00
@impl true
def init(instances) do
children =
Enum.map(instances, fn conf ->
%{
id: Keyword.get(conf, :hostname),
start: {PGSQLWatcher, :start_link, [conf]}
}
end)
2022-02-19 10:18:05 +01:00
opts = [strategy: :one_for_one]
Supervisor.init(children, opts)
end
2022-02-19 10:18:05 +01:00
end