-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsupervisor.ex
More file actions
63 lines (54 loc) · 1.63 KB
/
supervisor.ex
File metadata and controls
63 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
defmodule PushEx.Supervisor do
use Supervisor
@shutdown_timeout 10_000
def start_link(opts) do
Supervisor.start_link(__MODULE__, opts)
end
def init(_) do
children =
[
PushExWeb.Config,
PushExWeb.Endpoint,
{PushExWeb.PushTracker, [pool_size: PushEx.Application.pool_size()]},
{PushEx.Push.Drainer, producer_ref: PushEx.Push.ItemProducer, shutdown: @shutdown_timeout}
] ++ ranch_connection_drainers() ++ socket_drainer()
opts = [strategy: :one_for_one, name: __MODULE__]
Supervisor.init(children, opts)
end
defp ranch_connection_drainers() do
ranch_connection_drainer_endpoints()
|> Enum.map(fn phx_endpoint_mod ->
%{
id: Module.concat(RanchConnectionDrainer, phx_endpoint_mod),
start: {RanchConnectionDrainer, :start_link, [phx_endpoint_mod]},
shutdown: @shutdown_timeout
}
end)
end
defp socket_drainer() do
if PushEx.Config.disconnect_sockets_on_shutdown() do
[
{PushExWeb.SocketDrainer, shutdown: @shutdown_timeout, ranch_refs: ranch_connection_drainer_endpoints()}
]
else
[]
end
end
defp ranch_connection_drainer_endpoints() do
ranch_connection_drainer_http() ++ ranch_connection_drainer_https()
end
defp ranch_connection_drainer_http() do
if Application.get_env(:push_ex, PushExWeb.Endpoint) |> Keyword.get(:http) do
[PushExWeb.Endpoint.HTTP]
else
[]
end
end
defp ranch_connection_drainer_https() do
if Application.get_env(:push_ex, PushExWeb.Endpoint) |> Keyword.get(:https) do
[PushExWeb.Endpoint.HTTPS]
else
[]
end
end
end