| 1 |
|
defmodule Elita.Kernel do |
| 2 |
|
import Supervisor, only: [start_link: 2] |
| 3 |
|
|
| 4 |
1 |
defdelegate registry_spec(opts), to: Registry, as: :child_spec |
| 5 |
|
|
| 6 |
|
@spec_map %{ |
| 7 |
|
id: __MODULE__, |
| 8 |
|
start: {__MODULE__, :start_link, [nil]}, |
| 9 |
|
type: :supervisor, |
| 10 |
|
restart: :permanent, |
| 11 |
|
shutdown: :infinity |
| 12 |
|
} |
| 13 |
|
|
| 14 |
1 |
def child_spec(_arg), do: @spec_map |
| 15 |
|
|
| 16 |
|
def start_link(_arg) do |
| 17 |
1 |
start_link(specs(), opts()) |
| 18 |
|
end |
| 19 |
|
|
| 20 |
1 |
defp specs, |
| 21 |
|
do: [ |
| 22 |
|
registry(), |
| 23 |
|
Elita.Bank, |
| 24 |
|
{DynamicSupervisor, spec()} |
| 25 |
|
] |
| 26 |
|
|
| 27 |
|
defp registry do |
| 28 |
1 |
registry_spec(keys: :unique, name: ElitaRegistry) |
| 29 |
|
end |
| 30 |
|
|
| 31 |
1 |
defp spec, |
| 32 |
|
do: [ |
| 33 |
|
name: Elita.Spawner, |
| 34 |
|
strategy: :one_for_one, |
| 35 |
|
max_restarts: 3, |
| 36 |
|
max_seconds: 30 |
| 37 |
|
] |
| 38 |
|
|
| 39 |
1 |
defp opts, |
| 40 |
|
do: [ |
| 41 |
|
strategy: :rest_for_one, |
| 42 |
|
name: Elita.Kernel, |
| 43 |
|
max_restarts: 3, |
| 44 |
|
max_seconds: 60 |
| 45 |
|
] |
| 46 |
|
end |