完善host的删除逻辑
This commit is contained in:
parent
381b44df9a
commit
5d143be3ef
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/2, get_name/1, get_alias_name/1, get_pid/1, handle/2, activate/2]).
|
-export([start_link/2, get_name/1, get_alias_name/1, get_pid/1, handle/2, activate/2]).
|
||||||
-export([get_metric/1, get_status/1]).
|
-export([get_metric/1, get_status/1, kill/1]).
|
||||||
%% 通讯相关
|
%% 通讯相关
|
||||||
-export([pub/3, attach_channel/2, command/3]).
|
-export([pub/3, attach_channel/2, command/3]).
|
||||||
-export([deploy_container/3, start_container/2, stop_container/2, remove_container/2, kill_container/2, config_container/3, get_containers/1, await_reply/2]).
|
-export([deploy_container/3, start_container/2, stop_container/2, remove_container/2, kill_container/2, config_container/3, get_containers/1, await_reply/2]).
|
||||||
@ -61,6 +61,15 @@ get_alias_name(HostId0) when is_integer(HostId0) ->
|
|||||||
HostId = integer_to_binary(HostId0),
|
HostId = integer_to_binary(HostId0),
|
||||||
binary_to_atom(<<"iot_host_id:", HostId/binary>>).
|
binary_to_atom(<<"iot_host_id:", HostId/binary>>).
|
||||||
|
|
||||||
|
-spec kill(UUID :: binary()) -> no_return().
|
||||||
|
kill(UUID) when is_binary(UUID) ->
|
||||||
|
case whereis(get_name(UUID)) of
|
||||||
|
undefined ->
|
||||||
|
ok;
|
||||||
|
Pid ->
|
||||||
|
exit(Pid, kill)
|
||||||
|
end.
|
||||||
|
|
||||||
%% 处理消息
|
%% 处理消息
|
||||||
-spec handle(Pid :: pid(), Packet :: {atom(), any()}) -> no_return().
|
-spec handle(Pid :: pid(), Packet :: {atom(), any()}) -> no_return().
|
||||||
handle(Pid, Packet) when is_pid(Pid) ->
|
handle(Pid, Packet) when is_pid(Pid) ->
|
||||||
|
|||||||
@ -35,10 +35,23 @@ ensured_host_started(UUID) when is_binary(UUID) ->
|
|||||||
{ok, Pid}
|
{ok, Pid}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
delete_host(UUID) when is_binary(UUID) ->
|
delete_host(UUID) ->
|
||||||
Id = iot_host:get_name(UUID),
|
Id = iot_host:get_name(UUID),
|
||||||
ok = supervisor:terminate_child(?MODULE, Id),
|
case supervisor:terminate_child(?MODULE, Id) of
|
||||||
supervisor:delete_child(?MODULE, Id).
|
{error, running} ->
|
||||||
|
iot_host:kill(UUID),
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
case supervisor:delete_child(?MODULE, Id) of
|
||||||
|
{error, running} ->
|
||||||
|
%% ensure killed then delete again
|
||||||
|
iot_host:kill(UUID),
|
||||||
|
supervisor:delete_child(?MODULE, Id);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
child_spec(UUID) ->
|
child_spec(UUID) ->
|
||||||
Id = iot_host:get_name(UUID),
|
Id = iot_host:get_name(UUID),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user