Removed Supervisor.Spec
Supervisor.Spec is deprecated so moved to the modern format.master
parent
4fac5895db
commit
bd396dc3d4
|
@ -4,23 +4,17 @@ defmodule Discordirc do
|
||||||
"""
|
"""
|
||||||
use Application
|
use Application
|
||||||
|
|
||||||
alias Discordirc.IRC
|
alias Discordirc.IrcNetworkSupervisor
|
||||||
|
alias Discordirc.DiscordHandler
|
||||||
|
alias Discordirc.WebhookService
|
||||||
|
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
import Supervisor.Spec
|
children = [
|
||||||
|
{DiscordHandler, []},
|
||||||
|
{WebhookService, []},
|
||||||
|
{IrcNetworkSupervisor, []}
|
||||||
|
]
|
||||||
|
|
||||||
ircnets =
|
Supervisor.start_link(children, strategy: :one_for_one)
|
||||||
Application.get_env(:discordirc, :networks)
|
|
||||||
|> Enum.map(fn net -> worker(IRC, [net], id: net.network) end)
|
|
||||||
|
|
||||||
children =
|
|
||||||
ircnets ++
|
|
||||||
[
|
|
||||||
Discordirc.DiscordHandler,
|
|
||||||
Discordirc.WebhookService
|
|
||||||
]
|
|
||||||
|
|
||||||
options = [strategy: :one_for_one, name: Discordirc.Supervisor]
|
|
||||||
Supervisor.start_link(children, options)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
defmodule Discordirc.IrcNetworkSupervisor do
|
||||||
|
@moduledoc """
|
||||||
|
Supervises all of the IRC networks.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use Supervisor
|
||||||
|
|
||||||
|
alias Discordirc.IRC
|
||||||
|
|
||||||
|
def start_link(init_arg) do
|
||||||
|
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_init_arg) do
|
||||||
|
networks =
|
||||||
|
Application.get_env(:discordirc, :networks)
|
||||||
|
|> Enum.map(&%{start: {IRC, :start_link, [&1]}, id: &1.network})
|
||||||
|
|
||||||
|
Supervisor.init(networks, strategy: :one_for_one)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue