Permalink
Browse files

Fix api_sup after review

  • Loading branch information...
klen committed Jun 21, 2011
1 parent 2bff28e commit 79e97f759ff040e17d2d399e250586fb89bf66f3
Showing with 21 additions and 18 deletions.
  1. +21 −18 api/src/api_sup.erl
View
@@ -18,6 +18,7 @@
]).
-define( SERVER, ?MODULE ).
+-define( DEFAULT_LIMIT, 10 ).
%% @spec start_link() -> {ok, Pid} | ignore | { error, Other }
@@ -32,17 +33,29 @@ start_link() ->
init([]) ->
% Parse application options
+
+
+ % >> are you sure that here we will always have {ok, _} as a result
+ % Im not sure, but error here is the result of incorrectly configured application
+ % ----------
{ ok, Opts } = get_config(),
- { ok, Limit } = opt(Opts, num_seq),
+ { ok, Limit } = proplists:get_value(num_seq, Opts, {ok, ?DEFAULT_LIMIT}),
- SequenceServer = { api_server, { api_server, start_link, [ Limit ] }, permanent, 2000, worker, [ api_server ] },
- Children = [ SequenceServer ],
- RestartStrategy = { one_for_one, 4, 3600 },
- { ok, { RestartStrategy, Children } }
+ % >> just style change
+ % >> if there's more than one child, the following style is better (IMHO)
+ % Ok, not problem for me, because i have no coding style in erlang
+ % ----------
+ { ok, { { one_for_one, 4, 3600 }, [
+ { api_server, { api_server, start_link, [ Limit ] },
+ permanent, 2000, worker, [ api_server ] }
+ %, {...}
+ %, {...}
+ ] } }
.
+
%% @spec get_config() -> { ok, Terms }
%% @doc Get application config from conf or app file.
get_config() ->
@@ -52,19 +65,9 @@ get_config() ->
{ error, Error } ->
error_logger:info_msg("error ~p", [ Error ]),
Terms = application:get_all_env(api),
+ % >> I'd better use here ?MODULE instead of 'api'
+ % ?MODULE here have value 'api_sup' will it work?
+ % ----------
{ ok, Terms }
end
.
-
-
-%% @spec opt(Opts, Key) -> { ok, Value } | { undefined, undefined }
-%% @doc get option from options list
-opt([ { Key, Value } | _Rest ], Key) ->
- { ok, Value }
-;
-opt([ _H | [] ], _Key) ->
- { undefined, undefined }
-;
-opt([ _H | Rest ], Key) ->
- opt(Rest, Key)
-.

0 comments on commit 79e97f7

Please sign in to comment.