pooler_config.erl 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. %% @author Seth Falcon <seth@userprimary.net>
  2. %% @copyright 2012-2013 Seth Falcon
  3. %% @doc Helper module to transform app config proplists into pool records
  4. -module(pooler_config).
  5. -export([list_to_pool/1]).
  6. -include("pooler.hrl").
  7. -spec list_to_pool([{atom(), term()}]) -> #pool{}.
  8. list_to_pool(P) ->
  9. #pool{
  10. name = req(name, P),
  11. group = ?gv(group, P),
  12. max_count = req(max_count, P),
  13. init_count = req(init_count, P),
  14. start_mfa = req(start_mfa, P),
  15. add_member_retry = ?gv(add_member_retry, P, ?DEFAULT_ADD_RETRY),
  16. cull_interval = ?gv(cull_interval, P, ?DEFAULT_CULL_INTERVAL),
  17. max_age = ?gv(max_age, P, ?DEFAULT_MAX_AGE),
  18. member_start_timeout = ?gv(member_start_timeout, P, ?DEFAULT_MEMBER_START_TIMEOUT),
  19. metrics_mod = ?gv(metrics_mod, P, pooler_no_metrics)}.
  20. %% Return `Value' for `Key' in proplist `P' or crashes with an
  21. %% informative message if no value is found.
  22. req(Key, P) ->
  23. case lists:keyfind(Key, 1, P) of
  24. false ->
  25. error({missing_required_config, Key, P});
  26. {Key, Value} ->
  27. Value
  28. end.