Allow to configure app wide woody event handlers (#20)

This commit is contained in:
Andrew Mayorov 2020-01-30 19:33:36 +03:00 committed by GitHub
commit 5a3c2b3efc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 15 deletions

View File

@ -53,6 +53,7 @@ stop(_State) ->
{ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init([]) ->
EventHandlers = bender_utils:get_woody_event_handlers(),
ChildSpec = woody_server:child_spec(
?MODULE,
#{
@ -61,12 +62,9 @@ init([]) ->
protocol_opts => get_protocol_opts(),
transport_opts => get_transport_opts(),
shutdown_timeout => get_shutdown_timeout(),
event_handler => [
scoper_woody_event_handler,
hay_woody_event_handler
],
event_handler => EventHandlers,
handlers => [get_handler_spec()],
additional_routes => get_routes()
additional_routes => get_routes(EventHandlers)
}
),
{ok, {
@ -116,12 +114,12 @@ get_handler_spec() ->
bender_handler
}}.
-spec get_routes() ->
-spec get_routes(woody:ev_handlers()) ->
[woody_server_thrift_http_handler:route(_)].
get_routes() ->
get_routes(EventHandlers) ->
RouteOptsEnv = genlib_app:env(?MODULE, route_opts, #{}),
RouteOpts = RouteOptsEnv#{event_handler => scoper_woody_event_handler},
RouteOpts = RouteOptsEnv#{event_handler => EventHandlers},
Generator = genlib_app:env(bender, generator, #{}),
Sequence = genlib_app:env(bender, sequence, #{}),
Handlers = [

View File

@ -2,6 +2,7 @@
-export([unique_id/0]).
-export([get_backend/2]).
-export([get_woody_event_handlers/0]).
-type woody_context() :: woody_context:ctx().
@ -40,9 +41,18 @@ get_backend(Service, WoodyCtx) ->
-spec get_woody_client(automaton()) ->
machinery_mg_client:woody_client().
get_woody_client(#{url := Url, event_handler := Handler} = Automaton) ->
get_woody_client(#{url := Url} = Automaton) ->
genlib_map:compact(#{
url => Url,
event_handler => Handler,
event_handler => get_woody_event_handlers(),
transport_opts => maps:get(transport_opts, Automaton, undefined)
}).
-spec get_woody_event_handlers() ->
woody:ev_handlers().
get_woody_event_handlers() ->
genlib_app:env(bender, woody_event_handlers, [
scoper_woody_event_handler,
hay_woody_event_handler
]).

View File

@ -8,10 +8,6 @@
path => <<"/v1/stateproc/bender_generator">>,
schema => machinery_mg_schema_generic,
url => <<"http://machinegun:8022/v1/automaton">>, % mandatory
event_handler => [
scoper_woody_event_handler,
hay_woody_event_handler
],
transport_opts => #{
max_connections => 1000
}
@ -21,7 +17,6 @@
path => <<"/v1/stateproc/bender_sequence">>,
schema => machinery_mg_schema_generic,
url => <<"http://machinegun:8022/v1/automaton">>, % mandatory
event_handler => scoper_woody_event_handler, % mandatory
transport_opts => #{
max_connections => 1000
}
@ -45,6 +40,18 @@
num_acceptors => 100 % size of acceptors pool, default is 10
}},
{woody_event_handlers, [
hay_woody_event_handler,
{scoper_woody_event_handler, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000,
max_printable_string_length => 80
}
}
}}
]},
{health_check, #{
disk => {erl_health, disk , ["/", 99]},
memory => {erl_health, cg_memory, [99]},