Add `is_bridge_exist` api in emqx_bridge_sup

This commit is contained in:
Gilbert Wong 2019-04-09 11:32:37 +08:00 committed by Gilbert
parent 8cfd080a97
commit 627ea0afe8
1 changed files with 9 additions and 2 deletions

View File

@ -20,11 +20,12 @@
%% APIs
-export([ start_link/0
, start_link/1
, bridges/0
]).
-export([ create_bridge/2
, drop_bridge/1
, bridges/0
, is_bridge_exist/1
]).
%% supervisor callbacks
@ -58,6 +59,13 @@ bridge_spec({Name, Config}) ->
bridges() ->
[{Name, emqx_bridge:status(Pid)} || {Name, Pid, _, _} <- supervisor:which_children(?SUP)].
-spec(is_bridge_exist(atom() | pid()) -> boolean()).
is_bridge_exist(Id) ->
case supervisor:get_childspec(?SUP, Id) of
{ok, _ChildSpec} -> true;
{error, _Error} -> false
end.
create_bridge(Id, Config) ->
supervisor:start_child(?SUP, bridge_spec({Id, Config})).
@ -69,4 +77,3 @@ drop_bridge(Id) ->
?LOG(error, "[Bridge] Delete bridge failed", [Error]),
Error
end.