Skip to content
Newer
Older
100644 65 lines (54 sloc) 2.03 KB
d25d0f4 @astro supervisor
authored
1 -module(harvester_sup).
2
3 -behaviour(supervisor).
4
5 %% API
6 -export([start_link/0]).
7
8 %% Supervisor callbacks
9 -export([init/1]).
10
11 -define(SERVER, ?MODULE).
12
13 %%====================================================================
14 %% API functions
15 %%====================================================================
16 start_link() ->
17 supervisor:start_link({local, ?SERVER}, ?MODULE, []).
18
19 %%====================================================================
20 %% Supervisor callbacks
21 %%====================================================================
22 init([]) ->
cb622f1 @astro new worker
authored
23 {ok, ConfigWorkers} = config_workers(),
83cd1ae @astro tidy
authored
24 {ok,{{one_for_one,2,1}, [
d25d0f4 @astro supervisor
authored
25 {iconv, {iconv, start_link, []},
26 permanent, 1000, worker, [iconv]},
83cd1ae @astro tidy
authored
27 {tidy, {tidy, start_link, []},
28 permanent, 1000, worker, [tidy]},
d25d0f4 @astro supervisor
authored
29 {dns_cache, {dns_cache, start_link, []},
83cd1ae @astro tidy
authored
30 permanent, 2000, worker, [dns_cache, dns_worker]},
d25d0f4 @astro supervisor
authored
31 {http_client, {http_client, start_link, []},
cb622f1 @astro new worker
authored
32 permanent, 4000, worker, [http_client, http_connection]},
33 {updater, {updater, start_link, []},
94b7547 @astro webserver stuff, update_job
authored
34 permanent, 1000, worker, [updater]},
cb622f1 @astro new worker
authored
35 {notify, {notify, start_link, []},
94b7547 @astro webserver stuff, update_job
authored
36 permanent, 1000, worker, [notify]}
cb622f1 @astro new worker
authored
37 | ConfigWorkers
d25d0f4 @astro supervisor
authored
38 ]}}.
39
40 %%====================================================================
41 %% Internal functions
42 %%====================================================================
cb622f1 @astro new worker
authored
43
44 config_workers() ->
45 config_workers("faucheuse.cfg").
46
47 config_workers(Filename) ->
48 case file:consult(Filename) of
49 {error, {Line, erl_scan, scan}} ->
50 error_logger:error_msg("Syntax error in ~p, line ~p~n",
51 [Filename, Line]),
52 exit(parse_error);
53 {error, Reason} ->
54 error_logger:error_msg("Cannot open ~p: ~p~n",
55 [Filename, Reason]),
56 exit(file_error);
57 {ok, [WorkerConfig]} ->
94b7547 @astro webserver stuff, update_job
authored
58 {ok, lists:map(fun worker_config2config_workers/1,
59 WorkerConfig)}
cb622f1 @astro new worker
authored
60 end.
61
62 worker_config2config_workers({web, Port, Handlers}) ->
63 {webserver, {webserver, start_link, [Port, Handlers]},
94b7547 @astro webserver stuff, update_job
authored
64 permanent, 1000, supervisor, [webserver]}.
Something went wrong with that request. Please try again.