-
Notifications
You must be signed in to change notification settings - Fork 41
/
supervisor.ex
44 lines (36 loc) · 1.03 KB
/
supervisor.ex
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
defmodule Hammer.Supervisor do
@moduledoc """
Top-level Supervisor for the Hammer application.
Starts a set of poolboy pools based on provided configuration,
which are latter called to by the `Hammer` module.
See the Application module for configuration examples.
"""
use Supervisor
def start_link(config, opts) do
Supervisor.start_link(__MODULE__, config, opts)
end
# Single backend
def init(config) when is_tuple(config) do
children = [
to_pool_spec(:hammer_backend_single_pool, config)
]
Supervisor.init(children, strategy: :one_for_one)
end
# Multiple backends
def init(config) when is_list(config) do
children =
config
|> Enum.map(fn {k, c} -> to_pool_spec(:"hammer_backend_#{k}_pool", c) end)
Supervisor.init(children, strategy: :one_for_one)
end
# Private helpers
defp to_pool_spec(name, {mod, args}) do
opts = [
name: {:local, name},
worker_module: mod,
size: 4,
max_overflow: 4
]
:poolboy.child_spec(name, opts, args)
end
end