Skip to content

Commit

Permalink
Improve supervision tree
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Aug 3, 2023
1 parent 641710f commit 79c599f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 29 additions & 0 deletions lib/ex_turn/supervisor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule ExTURN.Supervisor do
@moduledoc false
use Supervisor

require Logger

@version Mix.Project.config()[:version]

@spec start_link(any()) :: Supervisor.on_start()
def start_link(_arg) do
Supervisor.start_link(__MODULE__, nil, name: __MODULE__)
end

@impl true
def init(_arg) do
Logger.info("Starting ExTURN v#{@version}")

listen_ip = Application.fetch_env!(:ex_turn, :listen_ip)
listen_port = Application.fetch_env!(:ex_turn, :listen_port)

children = [
{DynamicSupervisor, strategy: :one_for_one, name: ExTURN.AllocationSupervisor},
{Registry, keys: :unique, name: Registry.Allocations},
{ExTURN.Listener, [listen_ip, listen_port]},
]

Supervisor.init(children, strategy: :one_for_all)
end
end
13 changes: 1 addition & 12 deletions lib/ex_turn_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@ defmodule ExTURN.App do
@moduledoc false
use Application

require Logger

@version Mix.Project.config()[:version]

@impl true
def start(_, _) do
Logger.info("Starting ExTURN v#{@version}...")

listen_ip = Application.fetch_env!(:ex_turn, :listen_ip)
listen_port = Application.fetch_env!(:ex_turn, :listen_port)

auth_provider_ip = Application.fetch_env!(:ex_turn, :auth_provider_ip)
auth_provider_port = Application.fetch_env!(:ex_turn, :auth_provider_port)
use_tls? = Application.fetch_env!(:ex_turn, :auth_provider_use_tls?)
Expand All @@ -34,11 +25,9 @@ defmodule ExTURN.App do
end

children = [
ExTURN.Supervisor,
{TelemetryMetricsPrometheus,
metrics: metrics(), plug_cowboy_opts: [ip: metrics_ip, port: metrics_port]},
{DynamicSupervisor, strategy: :one_for_one, name: ExTURN.AllocationSupervisor},
{Registry, keys: :unique, name: Registry.Allocations},
{ExTURN.Listener, [listen_ip, listen_port]},
{Bandit,
[plug: ExTURN.AuthProvider, ip: auth_provider_ip, port: auth_provider_port] ++ scheme_opts}
]
Expand Down

0 comments on commit 79c599f

Please sign in to comment.