Refactor portal supervisor

This commit is contained in:
Gilbert Wong 2019-02-25 17:49:41 +08:00
parent ec37225333
commit ae92acf30f
1 changed files with 7 additions and 16 deletions

View File

@ -28,20 +28,12 @@ start_link(Name) ->
supervisor:start_link({local, Name}, ?MODULE, Name). supervisor:start_link({local, Name}, ?MODULE, Name).
init(?SUP) -> init(?SUP) ->
Sp = fun(Name) ->
#{id => Name,
start => {?MODULE, start_link, [Name]},
restart => permanent,
shutdown => 5000,
type => supervisor,
modules => [?MODULE]
}
end,
{ok, {{one_for_one, 5, 10}, [Sp(?WORKER_SUP)]}};
init(?WORKER_SUP) ->
BridgesConf = emqx_config:get_env(bridges, []), BridgesConf = emqx_config:get_env(bridges, []),
BridgesSpec = lists:map(fun portal_spec/1, BridgesConf), BridgeSpec = lists:map(fun portal_spec/1, BridgesConf),
{ok, {{one_for_one, 10, 100}, BridgesSpec}}. SupFlag = #{strategy => one_for_one,
intensity => 10,
period => 100},
{ok, {SupFlag, BridgeSpec}}.
portal_spec({Name, Config}) -> portal_spec({Name, Config}) ->
#{id => Name, #{id => Name,
@ -49,9 +41,8 @@ portal_spec({Name, Config}) ->
restart => permanent, restart => permanent,
shutdown => 5000, shutdown => 5000,
type => worker, type => worker,
modules => [emqx_portal] modules => [emqx_portal]}.
}.
-spec(portals() -> [{node(), map()}]). -spec(portals() -> [{node(), map()}]).
portals() -> portals() ->
[{Name, emqx_portal:status(Pid)} || {Name, Pid, _, _} <- supervisor:which_children(?WORKER_SUP)]. [{Name, emqx_portal:status(Pid)} || {Name, Pid, _, _} <- supervisor:which_children(?SUP)].