Allow to configure app wide woody event handlers

This commit is contained in:
Andrew Mayorov 2020-01-30 15:22:34 +03:00
parent 17ed22fbb5
commit 24eb8aa146
3 changed files with 30 additions and 15 deletions

View File

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

View File

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

View File

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