Commit | Line | Data |
---|---|---|
d2a0e2f9 SK |
1 | -module(god). |
2 | -behaviour(supervisor). | |
3 | ||
4 | ||
5 | %% API | |
6 | -export([start_link/2]). | |
7 | ||
8 | %% Callbacks | |
9 | -export([init/1]). | |
10 | ||
11 | ||
12 | %% Helper macro for declaring children of supervisor | |
13 | -define(CHILD(Type, I, Args), {I, {I, start_link, Args}, permanent, 5000, Type, [I]}). | |
14 | ||
15 | ||
16 | %% ============================================================================ | |
17 | %% API | |
18 | %% ============================================================================ | |
19 | ||
20 | start_link(X, CellData) -> | |
21 | supervisor:start_link({local, ?MODULE}, ?MODULE, [X, CellData]). | |
22 | ||
23 | ||
24 | %% ============================================================================ | |
25 | %% Callbacks | |
26 | %% ============================================================================ | |
27 | ||
28 | init([X, CellData]) -> | |
29 | CellNames = [Name || {_, Name, _} <- CellData], | |
30 | RestartStrategy = {one_for_one, 5, 10}, | |
31 | Cells = [spec_cell(Datum) || Datum <- CellData], | |
32 | Time = ?CHILD(worker, time, [X, CellNames]), | |
33 | Children = Cells ++ [Time], | |
34 | {ok, {RestartStrategy, Children}}. | |
35 | ||
36 | ||
37 | spec_cell({_, Name, _}=Datum) -> | |
38 | M = cell, | |
39 | F = start_link, | |
40 | A = [Datum], | |
41 | {Name, {M, F, A}, permanent, 5000, worker, [M]}. | |
42 | ||
43 | %{ID, {ID, start_link, Args}, permanent, 5000, Type, [ID]}. | |
44 | ||
45 | ||
46 | ||
47 |