Files
omnibot/lib/plugin/supervisor.ex
Alek Ratzloff c43c075588 Minor changes all around
* Wordbot does not IO.inspect() the winners of the round
* Split Omnibot.Plugin.base_children/1 into base_children_before/1 and
  base_children_after/1 for plugins that come before and after the
  children in the module
* Other minor changes

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-14 19:13:43 -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_one)
end
end