Finish plugin and routing overhaul, there's a new model in town:
* Plugins all derive from Omnibot.Plugin. There still is a base plugin, in case we want to have another plugin backend instead of a GenServer * All plugins are monitored by a unique Plugin.Supervisor, which is in turn started by the PluginSupervisor (yes this is confusing, yes it needs to be renamed) * Any other auxiliary child processes may be started through the Plugin.children/1 function. * By default, plugins have a CfgState process which is an Agent that keeps track of the plugin's configuration and state * Plugin API is now called through the GenServer backend for better synchronicity. * Very few changes to the front-facing Plugin API, which is nice Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
28
lib/plugin/supervisor.ex
Normal file
28
lib/plugin/supervisor.ex
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
state = plugin.on_init(cfg)
|
||||
children = IO.inspect(plugin.plugin_children(cfg, state))
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user