Files
omnibot/lib/supervisor.ex
Alek Ratzloff 2f378dd438 Finish removing Omnibot.State functions
Omnibot.State shouldn't be used anywhere anymore except as a GenServer
being started up in the supervisor.

Also, configuration must be loaded through Config.load/1 rather than
being constructed, because everything expects a tuple of {plugin,
config} now.

Finally, Omnibot.Core must be added to the configuration in order for
basic functionality.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:23:53 -07:00

30 lines
863 B
Elixir

defmodule Omnibot.Supervisor do
@moduledoc false
use Supervisor
require IEx
alias Omnibot.Config
def start_link(opts) do
Supervisor.start_link(__MODULE__, :ok, opts)
end
@impl true
def init(:ok) do
cfg = System.get_env("OMNIBOT_CFG", "omnibot.exs") |> Config.load()
# TODO : move cfg to its own process so reloading it is as simple as killing the process
children = [
{Task.Supervisor, name: Omnibot.RouterSupervisor, strategy: :one_for_one},
{Omnibot.State, cfg: cfg, name: Omnibot.State},
{Omnibot.PluginManager, cfg: cfg, name: Omnibot.PluginManager},
] ++ unless IEx.started?(),
do: [{Omnibot.Irc, cfg: cfg, name: Omnibot.Irc}],
else: []
# :one_for_all here because the RouterSupervisor and IRC server are co-dependent
Supervisor.init(children, strategy: :one_for_all)
end
end