Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Comment things a bit more, add some tests

  • Loading branch information...
commit da0507a8d5b04603ccb4aeae4c254ab06dca073c 1 parent eb4908e
Mitchell Hashimoto authored
28 apps/lifeguard/src/lifeguard_ds_manager_sup.erl
... ... @@ -1,10 +1,24 @@
  1 +%% @doc This is the data source manager supervisor. It is responsible
  2 +%% for running the actual data source manager as well as each of the
  3 +%% actual data sources.
  4 +
1 5 -module(lifeguard_ds_manager_sup).
2 6 -behavior(supervisor).
3 7 -export([start_link/1, init/1]).
4 8
  9 +-ifdef(TEST).
  10 +-include_lib("eunit/include/eunit.hrl").
  11 +-endif.
  12 +
5 13 start_link(DataSources) ->
  14 + % There is only ever one data source manager, so we register it
  15 + % locally with our module name so that we can access it from anywhere.
6 16 supervisor:start_link({local, ?MODULE}, ?MODULE, DataSources).
7 17
  18 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19 +% supervisor callbacks
  20 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  21 +
8 22 init(DataSources) ->
9 23 % Define the manager...
10 24 Manager = {data_source_manager,
@@ -16,7 +30,21 @@ init(DataSources) ->
16 30
17 31 {ok, {{one_for_one, 10, 10}, [Manager | SourceSpecs]} }.
18 32
  33 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34 +% Internal Methods
  35 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36 +
19 37 data_source_spec({Name, Module, Args}) ->
20 38 {{data_source, Name},
21 39 {Module, start_link, [Name, Args]},
22 40 permanent, 30000, worker, [Module]}.
  41 +
  42 +-ifdef(TEST).
  43 +
  44 +data_source_spec_test() ->
  45 + Expected = {{data_source, "garbage"},
  46 + {my_module, start_link, ["garbage", [arg]]},
  47 + permanent, 30000, worker, [my_module]},
  48 + Expected = data_source_spec({"garbage", my_module, [arg]}).
  49 +
  50 +-endif.
5 apps/lifeguard/src/lifeguard_sup.erl
@@ -23,9 +23,14 @@ start_link() ->
23 23 %% ===================================================================
24 24
25 25 init([]) ->
  26 + % Get the data sources from the application configuration
26 27 {ok, DataSources} = application:get_env(data_sources),
  28 +
  29 + % Run the data store manager supervisor
27 30 DSManager = {data_store_manager_sup,
28 31 {lifeguard_ds_manager_sup, start_link, [DataSources]},
29 32 permanent, 30000, supervisor, [lifeguard_ds_manager_sup]},
  33 +
  34 + % Return the full spec
30 35 Children = [DSManager],
31 36 {ok, { {one_for_one, 5, 10}, Children} }.

0 comments on commit da0507a

Please sign in to comment.
Something went wrong with that request. Please try again.