2020-06-12 17:29:35 -04:00
|
|
|
defmodule Omnibot.Supervisor do
|
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
|
|
use Supervisor
|
2020-07-01 12:04:51 -07:00
|
|
|
require IEx
|
2020-08-11 15:23:53 -07:00
|
|
|
alias Omnibot.Config
|
2020-06-12 17:29:35 -04:00
|
|
|
|
|
|
|
|
def start_link(opts) do
|
|
|
|
|
Supervisor.start_link(__MODULE__, :ok, opts)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def init(:ok) do
|
2020-08-11 15:23:53 -07:00
|
|
|
cfg = System.get_env("OMNIBOT_CFG", "omnibot.exs") |> Config.load()
|
2020-06-12 17:29:35 -04:00
|
|
|
|
2020-08-11 12:48:28 -07:00
|
|
|
# TODO : move cfg to its own process so reloading it is as simple as killing the process
|
2020-06-12 17:29:35 -04:00
|
|
|
children = [
|
|
|
|
|
{Task.Supervisor, name: Omnibot.RouterSupervisor, strategy: :one_for_one},
|
|
|
|
|
{Omnibot.State, cfg: cfg, name: Omnibot.State},
|
2020-08-11 12:48:28 -07:00
|
|
|
{Omnibot.PluginManager, cfg: cfg, name: Omnibot.PluginManager},
|
2020-06-14 16:47:44 -04:00
|
|
|
] ++ unless IEx.started?(),
|
2020-08-11 12:48:28 -07:00
|
|
|
do: [{Omnibot.Irc, cfg: cfg, name: Omnibot.Irc}],
|
2020-06-14 16:47:44 -04:00
|
|
|
else: []
|
2020-06-12 17:29:35 -04:00
|
|
|
|
|
|
|
|
# :one_for_all here because the RouterSupervisor and IRC server are co-dependent
|
|
|
|
|
Supervisor.init(children, strategy: :one_for_all)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|