Skip to content

Commit

Permalink
Merge pull request #3170 from esl/mu-hosttype-wpool
Browse files Browse the repository at this point in the history
Hosttypyfy wpool
  • Loading branch information
chrzaszcz authored Jul 13, 2021
2 parents 7b0ed38 + 91f57d2 commit f86f1d1
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 204 deletions.
25 changes: 15 additions & 10 deletions src/event_pusher/mod_event_pusher_push.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,31 @@
%%--------------------------------------------------------------------
%% gen_mod callbacks
%%--------------------------------------------------------------------
-spec start(Host :: jid:server(), Opts :: list()) -> any().
-spec start(HostType :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> any().
start(Host, Opts) ->
?LOG_INFO(#{what => event_pusher_starting, server => Host}),

WpoolOpts = [{strategy, available_worker} | gen_mod:get_opt(wpool, Opts, [])],
{ok, _} = mongoose_wpool:start(generic, Host, pusher_push, WpoolOpts),

start_pool(Host, Opts),
gen_mod:start_backend_module(?MODULE, Opts, [enable, disable, get_publish_services]),
mod_event_pusher_push_backend:init(Host, Opts),

mod_event_pusher_push_plugin:init(Host),
init_iq_handlers(Host, Opts),
ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 90),
ok.

start_pool(Host, Opts) ->
WpoolOpts = wpool_opts(Opts),
{ok, _} = mongoose_wpool:start(generic, Host, pusher_push, WpoolOpts).

-spec wpool_opts(gen_mod:module_opts()) -> mongoose_wpool:pool_opts().
wpool_opts(Opts) ->
[{strategy, available_worker} | gen_mod:get_opt(wpool, Opts, [])].

init_iq_handlers(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_PUSH, ?MODULE,
iq_handler, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PUSH, ?MODULE,
iq_handler, IQDisc),

ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 90),
ok.
iq_handler, IQDisc).

-spec stop(Host :: jid:server()) -> ok.
stop(Host) ->
Expand Down
20 changes: 15 additions & 5 deletions src/event_pusher/mod_event_pusher_sns.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,26 @@
%% Types
-export_type([user_guid/0, topic_arn/0, topic/0, attributes/0]).

-spec start(Host :: jid:server(), Opts :: proplists:proplist()) -> ok.
-spec start(Host :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok.
start(Host, Opts) ->
application:ensure_all_started(erlcloud),
application:ensure_all_started(worker_pool),
start_pool(Host, Opts),
ok.

WorkerNum = gen_mod:get_opt(pool_size, Opts, 100),
{ok, _} = mongoose_wpool:start(generic, Host, pusher_sns,
[{workers, WorkerNum}, {strategy, available_worker}]),
-spec start_pool(Host :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) ->
term().
start_pool(Host, Opts) ->
{ok, _} = mongoose_wpool:start(generic, Host, pusher_sns, pool_opts(Opts)).

ok.
-spec pool_opts(gen_mod:module_opts()) -> mongoose_wpool:pool_opts().
pool_opts(Opts) ->
WorkerNum = get_worker_num(Opts),
[{workers, WorkerNum}, {strategy, available_worker}].

-spec get_worker_num(gen_mod:module_opts()) -> pos_integer().
get_worker_num(Opts) ->
gen_mod:get_opt(pool_size, Opts, 100).

-spec stop(Host :: jid:server()) -> ok.
stop(Host) ->
Expand Down
20 changes: 12 additions & 8 deletions src/mod_push_service_mongoosepush.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@
%% Module callbacks
%%--------------------------------------------------------------------

-spec start(Host :: jid:server(), Opts :: list()) -> any().
-spec start(Host :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> any().
start(Host, Opts) ->
?LOG_INFO(#{what => push_service_starting, server => Host}),

MaxHTTPConnections = gen_mod:get_opt(max_http_connections, Opts, 100),
{ok, _} = mongoose_wpool:start(generic, Host, mongoosepush_service,
[{strategy, available_worker},
{workers, MaxHTTPConnections}]),

start_pool(Host, Opts),
%% Hooks
ejabberd_hooks:add(push_notifications, Host, ?MODULE, push_notifications, 10),

ok.

-spec start_pool(mongooseim:host_type(), gen_mod:module_opts()) -> term().
start_pool(Host, Opts) ->
{ok, _} = mongoose_wpool:start(generic, Host, mongoosepush_service, pool_opts(Opts)).

-spec pool_opts(gen_mod:module_opts()) -> mongoose_wpool:pool_opts().
pool_opts(Opts) ->
MaxHTTPConnections = gen_mod:get_opt(max_http_connections, Opts, 100),
[{strategy, available_worker},
{workers, MaxHTTPConnections}].

-spec stop(Host :: jid:server()) -> ok.
stop(Host) ->
ejabberd_hooks:delete(push_notifications, Host, ?MODULE, push_notifications, 10),
Expand Down
Loading

0 comments on commit f86f1d1

Please sign in to comment.