This commit is contained in:
anlicheng 2025-11-07 16:14:57 +08:00
parent 36a64939da
commit 4a294ec8ee

View File

@ -131,11 +131,6 @@ remove_container(Pid, ContainerName) when is_pid(Pid), is_binary(ContainerName)
EncCallBin = message_codec:encode(?MESSAGE_JSONRPC_REQUEST, Request),
gen_statem:call(Pid, {jsonrpc_call, self(), EncCallBin}).
%-spec task_log(Pid :: pid(), TaskId :: integer()) -> {ok, Ref :: reference()} | {error, Reason :: any()}.
%task_log(Pid, TaskId) when is_pid(Pid), is_integer(TaskId) ->
% TaskLogBin = message_pb:encode_msg(#fetch_task_log{task_id = TaskId}),
% gen_statem:call(Pid, {jsonrpc_call, self(), ?PUSH_TASK_LOG, TaskLogBin}).
-spec await_reply(Ref :: reference(), Timeout :: integer()) -> {ok, Result :: binary()} | {error, Reason :: binary()}.
await_reply(Ref, Timeout) when is_reference(Ref), is_integer(Timeout) ->
receive
@ -314,7 +309,6 @@ handle_event({call, From}, {attach_channel, ChannelPid}, StateName, State = #sta
erlang:monitor(process, ChannelPid),
%% 线
ChangeResult = iot_api:change_host_status(UUID, ?HOST_ONLINE),
report_event(UUID, ?HOST_ONLINE),
lager:debug("[iot_host] host_id(attach_channel) uuid: ~p, will change status, result: ~p", [UUID, ChangeResult]),
{keep_state, State#state{channel_pid = ChannelPid, has_session = true}, [{reply, From, ok}]};
%%
@ -412,8 +406,7 @@ handle_event(info, {timeout, _, heartbeat_ticker}, _, State = #state{uuid = UUID
?HOST_OFFLINE ->
lager:debug("[iot_host] host: ~p, host_maybe_offline, host now is offline, do nothing", [UUID]);
?HOST_ONLINE ->
iot_api:change_host_status(UUID, ?HOST_OFFLINE),
report_event(UUID, ?HOST_OFFLINE)
iot_api:change_host_status(UUID, ?HOST_OFFLINE)
end,
%% channel
@ -463,26 +456,6 @@ get_route_key(<<"">>) ->
get_route_key(RouteKey) when is_binary(RouteKey) ->
RouteKey.
-spec report_event(UUID :: binary(), NewStatus :: integer()) -> no_return().
report_event(UUID, NewStatus) when is_binary(UUID), is_integer(NewStatus) ->
TextMap = #{
0 => <<"离线"/utf8>>,
1 => <<"在线"/utf8>>
},
%%
Timestamp = iot_util:timestamp_of_seconds(),
FieldsList = [#{
<<"key">> => <<"host_status">>,
<<"value">> => NewStatus,
<<"value_text">> => maps:get(NewStatus, TextMap),
<<"unit">> => 0,
<<"type">> => <<"DI">>,
<<"name">> => <<"主机状态"/utf8>>,
<<"timestamp">> => Timestamp
}],
lager:debug("[iot_host] host_uuid: ~p, route fields: ~p", [UUID, FieldsList]).
%% state转换成map
state_map(#state{host_id = HostId, uuid = UUID, has_session = HasSession, heartbeat_counter = HeartbeatCounter, channel_pid = ChannelPid, metrics = Metrics}) ->
#{