Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosttypyfy wpool #3170

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, I think that variable names should agree between the spec and the implementation. We could either change to HostType or leave Host in both places.

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