Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Comment things a bit more, add some tests

  • Loading branch information...
commit da0507a8d5b04603ccb4aeae4c254ab06dca073c 1 parent eb4908e
@mitchellh authored
View
28 apps/lifeguard/src/lifeguard_ds_manager_sup.erl
@@ -1,10 +1,24 @@
+%% @doc This is the data source manager supervisor. It is responsible
+%% for running the actual data source manager as well as each of the
+%% actual data sources.
+
-module(lifeguard_ds_manager_sup).
-behavior(supervisor).
-export([start_link/1, init/1]).
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+-endif.
+
start_link(DataSources) ->
+ % There is only ever one data source manager, so we register it
+ % locally with our module name so that we can access it from anywhere.
supervisor:start_link({local, ?MODULE}, ?MODULE, DataSources).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% supervisor callbacks
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
init(DataSources) ->
% Define the manager...
Manager = {data_source_manager,
@@ -16,7 +30,21 @@ init(DataSources) ->
{ok, {{one_for_one, 10, 10}, [Manager | SourceSpecs]} }.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Internal Methods
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
data_source_spec({Name, Module, Args}) ->
{{data_source, Name},
{Module, start_link, [Name, Args]},
permanent, 30000, worker, [Module]}.
+
+-ifdef(TEST).
+
+data_source_spec_test() ->
+ Expected = {{data_source, "garbage"},
+ {my_module, start_link, ["garbage", [arg]]},
+ permanent, 30000, worker, [my_module]},
+ Expected = data_source_spec({"garbage", my_module, [arg]}).
+
+-endif.
View
5 apps/lifeguard/src/lifeguard_sup.erl
@@ -23,9 +23,14 @@ start_link() ->
%% ===================================================================
init([]) ->
+ % Get the data sources from the application configuration
{ok, DataSources} = application:get_env(data_sources),
+
+ % Run the data store manager supervisor
DSManager = {data_store_manager_sup,
{lifeguard_ds_manager_sup, start_link, [DataSources]},
permanent, 30000, supervisor, [lifeguard_ds_manager_sup]},
+
+ % Return the full spec
Children = [DSManager],
{ok, { {one_for_one, 5, 10}, Children} }.
Please sign in to comment.
Something went wrong with that request. Please try again.