TD-720: add transport_opts to client config (#13)

* TD-720: add transport_opts to client config

* TD-720: bump git workflow

---------

Co-authored-by: anatoliy.losev <losto@nix>
This commit is contained in:
ttt161 2023-09-27 10:27:03 +03:00 committed by GitHub
parent 79d9d0144e
commit 2ce8d4aeee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 7 deletions

View File

@ -30,7 +30,7 @@ jobs:
run:
name: Run checks
needs: setup
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.1
uses: valitydev/erlang-workflows/.github/workflows/erlang-parallel-build.yml@v1.0.12
with:
otp-version: ${{ needs.setup.outputs.otp-version }}
rebar-version: ${{ needs.setup.outputs.rebar-version }}

View File

@ -11,8 +11,15 @@
org_management
| bouncer.
-type transport_opts() :: #{
pool := atom(),
max_connections => non_neg_integer(),
timeout => non_neg_integer()
}.
-type client_config() :: #{
url := woody:url(),
transport_opts => transport_opts(),
timeout => non_neg_integer(),
retries => #{woody:func() | '_' => genlib_retry:strategy()}
}.
@ -27,15 +34,12 @@ call(ServiceName, Function, Args, Context) ->
-spec call(service_name(), woody:func(), woody:args(), context(), woody:ev_handler()) -> woody:result().
call(ServiceName, Function, Args, Context0, EventHandler) ->
Config = get_service_client_config(ServiceName),
Opts = get_service_client_opts(Config, EventHandler),
Deadline = get_service_deadline(Config),
Context1 = set_deadline(Deadline, set_default_deadline(Context0)),
Retry = get_service_retry(Function, Config),
Service = get_service_modname(ServiceName),
Request = {Service, Function, Args},
Opts = #{
url => get_service_client_url(Config),
event_handler => EventHandler
},
call_retry(Request, Context1, Opts, Retry).
call_retry(Request, Context, Opts, Retry) ->
@ -75,8 +79,13 @@ get_service_client_config(ServiceName) ->
ServiceClients = genlib_app:env(bouncer_client, service_clients, #{}),
maps:get(ServiceName, ServiceClients, #{}).
get_service_client_url(ClientConfig) ->
maps:get(url, ClientConfig).
-spec get_service_client_opts(client_config(), woody:ev_handler()) -> woody_client:options().
get_service_client_opts(#{url := Url} = Config, EventHandler) ->
#{
url => Url,
transport_opts => maps:get(transport_opts, Config, #{}),
event_handler => EventHandler
}.
-spec get_service_modname(service_name()) -> woody:service().
get_service_modname(org_management) ->

View File

@ -70,6 +70,13 @@ init_per_suite(Config) ->
{service_clients, #{
bouncer => #{
url => <<"http://bouncer:8022/">>,
transport_opts => #{
pool => priority,
max_connections => 2000,
%% hackney request timeout
timeout => ?TIMEOUT
},
%% woody_client:context() deadline
timeout => ?TIMEOUT,
retries => #{
'Judge' => ?RETRY_STRATEGY,