Add `is_bridge_exist` api in emqx_bridge_sup
This commit is contained in:
parent
8cfd080a97
commit
627ea0afe8
|
@ -20,11 +20,12 @@
|
||||||
%% APIs
|
%% APIs
|
||||||
-export([ start_link/0
|
-export([ start_link/0
|
||||||
, start_link/1
|
, start_link/1
|
||||||
, bridges/0
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ create_bridge/2
|
-export([ create_bridge/2
|
||||||
, drop_bridge/1
|
, drop_bridge/1
|
||||||
|
, bridges/0
|
||||||
|
, is_bridge_exist/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% supervisor callbacks
|
%% supervisor callbacks
|
||||||
|
@ -58,6 +59,13 @@ bridge_spec({Name, Config}) ->
|
||||||
bridges() ->
|
bridges() ->
|
||||||
[{Name, emqx_bridge:status(Pid)} || {Name, Pid, _, _} <- supervisor:which_children(?SUP)].
|
[{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) ->
|
create_bridge(Id, Config) ->
|
||||||
supervisor:start_child(?SUP, bridge_spec({Id, Config})).
|
supervisor:start_child(?SUP, bridge_spec({Id, Config})).
|
||||||
|
|
||||||
|
@ -69,4 +77,3 @@ drop_bridge(Id) ->
|
||||||
?LOG(error, "[Bridge] Delete bridge failed", [Error]),
|
?LOG(error, "[Bridge] Delete bridge failed", [Error]),
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue