2121
2222-include (" kinetic.hrl" ).
2323
24- -define (EHTTPC_POOL , kinetic_pool ).
25-
2624% application behaviour
2725
2826-spec start () -> ok | {error , any ()}.
@@ -34,17 +32,21 @@ stop() ->
3432 application :stop (kinetic ).
3533
3634start (Opts ) when is_list (Opts ) ->
37- start_pool (Opts ),
35+ start_pool (),
3836 kinetic_sup :start_link (Opts ).
3937
4038-spec start (normal | {takeover , node ()} | {failover , node ()}, any ()) -> {ok , pid ()}.
4139start (_ , Opts ) ->
42- start_pool (Opts ),
40+ start_pool (),
4341 kinetic_sup :start_link (Opts ).
4442
4543-spec stop (any ()) -> ok .
4644stop (_ ) ->
47- ehttpc_sup :stop_pool (? EHTTPC_POOL ),
45+ lists :foreach (fun (Region ) ->
46+ PoolName = kinetic_utils :pool_name (Region ),
47+ ok = ehttpc_sup :stop_pool (PoolName )
48+ end ,
49+ kinetic_utils :regions ()),
4850 ok .
4951
5052% Public API
@@ -281,7 +283,8 @@ execute(Operation, Payload, Opts) ->
281283 signed_headers => SignedHeaders ,
282284 aws_date => Date },
283285 iolist_to_binary (Body ))],
284- Worker = ehttpc_pool :pick_worker (? EHTTPC_POOL ),
286+ PoolName = kinetic_utils :pool_name (Region ),
287+ Worker = ehttpc_pool :pick_worker (PoolName ),
285288 case ehttpc :request (Worker , post , {" /" , Headers , Body }, Timeout ) of
286289 {ok , 200 , _ , ResponseBody } ->
287290 {ok , kinetic_utils :decode (ResponseBody )};
@@ -305,19 +308,15 @@ get_value(Key, TupleList) ->
305308 {Key , Value } = lists :keyfind (Key , 1 , TupleList ),
306309 Value .
307310
308- start_pool (Opts ) ->
309- Region =
310- case proplists :get_value (region , Opts , undefined ) of
311- undefined ->
312- {ok , Zone } = imds :zone (),
313- kinetic_utils :region (Zone );
314- R ->
315- R
316- end ,
317- Endpoint = kinetic_utils :endpoint (Region ),
311+ start_pool () ->
318312 PoolSize = application :get_env (? MODULE , pool_size , 100 ),
319- ehttpc_sup :start_pool (? EHTTPC_POOL ,
320- [{host , Endpoint },
321- {port , 443 },
322- {pool_size , PoolSize },
323- {gun_opts , [{transport , tls }]}]).
313+ lists :foreach (fun (Region ) ->
314+ PoolName = kinetic_utils :pool_name (Region ),
315+ Endpoint = kinetic_utils :endpoint (Region ),
316+ ehttpc_sup :start_pool (PoolName ,
317+ [{host , Endpoint },
318+ {port , 443 },
319+ {pool_size , PoolSize },
320+ {gun_opts , [{transport , tls }]}])
321+ end ,
322+ kinetic_utils :regions ()).
0 commit comments