fix heartbeat
This commit is contained in:
parent
aa4a62f3e8
commit
7fd82ac61d
@ -307,7 +307,8 @@ handle_event(cast, {handle, {ping, Metrics}}, ?STATE_ACTIVATED, State = #state{u
|
|||||||
{keep_state, State#state{metrics = Metrics}};
|
{keep_state, State#state{metrics = Metrics}};
|
||||||
|
|
||||||
%% 心跳机制
|
%% 心跳机制
|
||||||
handle_event(cast, heartbeat, _, State = #state{heartbeat_counter = HeartbeatCounter}) ->
|
handle_event(cast, heartbeat, _, State = #state{uuid = UUID, heartbeat_counter = HeartbeatCounter}) ->
|
||||||
|
maybe_mark_host_online(UUID),
|
||||||
{keep_state, State#state{heartbeat_counter = HeartbeatCounter + 1}};
|
{keep_state, State#state{heartbeat_counter = HeartbeatCounter + 1}};
|
||||||
|
|
||||||
%% 没有收到心跳包,主机下线, 设备状态不变
|
%% 没有收到心跳包,主机下线, 设备状态不变
|
||||||
@ -403,3 +404,18 @@ maybe_mark_host_offline(UUID) ->
|
|||||||
logger:warning("[iot_host] host: ~p, load status failed while marking offline: ~p", [UUID, Other]),
|
logger:warning("[iot_host] host: ~p, load status failed while marking offline: ~p", [UUID, Other]),
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec maybe_mark_host_online(binary()) -> ok.
|
||||||
|
maybe_mark_host_online(UUID) ->
|
||||||
|
case iot_api_client:get_host_by_uuid(UUID) of
|
||||||
|
{ok, #host_info{status = ?HOST_OFFLINE}} ->
|
||||||
|
_ = iot_api_client:change_host_status(UUID, ?HOST_ONLINE),
|
||||||
|
ok;
|
||||||
|
{ok, #host_info{status = ?HOST_ONLINE}} ->
|
||||||
|
ok;
|
||||||
|
{ok, #host_info{status = ?HOST_NOT_JOINED}} ->
|
||||||
|
ok;
|
||||||
|
Other ->
|
||||||
|
logger:warning("[iot_host] host: ~p, load status failed while marking online: ~p", [UUID, Other]),
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|||||||
@ -146,4 +146,4 @@ ensure_efka_client_table() ->
|
|||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
logger:debug("[iot_app] create efka_client table failed with error: ~p", [Reason]),
|
logger:debug("[iot_app] create efka_client table failed with error: ~p", [Reason]),
|
||||||
throw({init_tables, {efka_client, Reason}})
|
throw({init_tables, {efka_client, Reason}})
|
||||||
end.
|
end.
|
||||||
@ -21,6 +21,7 @@ loop(Transport = {udp, Server, _Sock}, Peer) ->
|
|||||||
Pid = iot_host:get_pid(HostUUID),
|
Pid = iot_host:get_pid(HostUUID),
|
||||||
iot_host:heartbeat(Pid),
|
iot_host:heartbeat(Pid),
|
||||||
loop(Transport, Peer);
|
loop(Transport, Peer);
|
||||||
{datagram, Server, _} ->
|
{datagram, Server, Packet} ->
|
||||||
exit(normal)
|
logger:warning("[udp_server] ignore invalid heartbeat packet from peer: ~p, packet: ~p", [Peer, Packet]),
|
||||||
end.
|
loop(Transport, Peer)
|
||||||
|
end.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user