fix device
This commit is contained in:
parent
30c0d6c198
commit
5cc6665a3d
@ -415,16 +415,22 @@ handle_event(info, {'EXIT', Pid, Reason}, StateName, State = #state{uuid = UUID,
|
||||
false ->
|
||||
{keep_state, State};
|
||||
{value, {DeviceUUID, _}} ->
|
||||
%% 避免数据异常,导致一直重启
|
||||
erlang:start_timer(5000, self(), {restart_device, DeviceUUID}),
|
||||
{keep_state, State#state{device_map = maps:remove(DeviceUUID, DeviceMap)}}
|
||||
end;
|
||||
|
||||
handle_event(info, {timeout, _, {restart_device, DeviceUUID}}, _, State = #state{uuid = UUID, device_map = DeviceMap}) ->
|
||||
%% 重启device进程不一定能成功,可能重启时,数据库已经删除了
|
||||
case iot_device:start_link(self(), DeviceUUID) of
|
||||
case catch iot_device:start_link(self(), DeviceUUID) of
|
||||
{ok, DevicePid} ->
|
||||
lager:debug("[iot_host] uuid: ~p, restart device: ~p, success", [UUID, DeviceUUID]),
|
||||
%% 采用的是同样的DeviceUUID,因此老的值会被覆盖
|
||||
NDeviceMap = maps:put(DeviceUUID, DevicePid, DeviceMap),
|
||||
{keep_state, State#state{device_map = NDeviceMap}};
|
||||
Error ->
|
||||
lager:warning("[iot_host] uuid: ~p, restart device: ~p, get error: ~p", [UUID, DeviceUUID, Error]),
|
||||
{keep_state, State}
|
||||
end
|
||||
end;
|
||||
|
||||
handle_event(EventType, EventContent, StateName, State) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user