Files
omnibot/lib/plugin/supervisor.ex
Alek Ratzloff 880f363792 Remove (supervisor) opts from Omnibot.Plugin opts, update Plugin.Supervisor to use :one_for_all strategy by default
Plugin opts no longer contains options for the supervisors that watch
plugins, and said supervisors now adopt the one_for_all strategy. This
is because these servers *generally* need one another to stay alive.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:37:55 -07:00

28 lines
672 B
Elixir

defmodule Omnibot.Plugin.Supervisor do
use Supervisor
def start_link(opts) do
{plugin, opts} = Keyword.pop(opts, :plugin)
{cfg, opts} = Keyword.pop(opts, :cfg)
start_link(plugin, cfg, opts)
end
def start_link(plugin, cfg, opts) when is_atom(plugin) do
Supervisor.start_link(__MODULE__, {plugin, cfg}, opts)
end
def child_spec(arg) do
id = Module.concat(arg[:plugin], Plugin.Supervisor)
%{
id: id,
start: {__MODULE__, :start_link, [arg]},
}
end
@impl true
def init({plugin, cfg}) when is_atom(plugin) do
children = plugin.plugin_children(cfg)
Supervisor.init(children, strategy: :one_for_all)
end
end