fix
This commit is contained in:
parent
f781d5e94b
commit
6375eaefe1
@ -27,7 +27,7 @@
|
|||||||
device_uuid :: binary(),
|
device_uuid :: binary(),
|
||||||
service_name :: binary(),
|
service_name :: binary(),
|
||||||
at :: integer(),
|
at :: integer(),
|
||||||
tags :: map(),
|
tags :: term(),
|
||||||
fields :: binary()
|
fields :: binary()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
|||||||
@ -128,24 +128,27 @@ handle_info({connect_reply, Reply}, State = #state{status = ?STATE_CONNECTING, t
|
|||||||
|
|
||||||
handle_info({auth_reply, {ok, ReplyBin}}, State = #state{status = ?STATE_AUTH, transport_pid = TransportPid}) ->
|
handle_info({auth_reply, {ok, ReplyBin}}, State = #state{status = ?STATE_AUTH, transport_pid = TransportPid}) ->
|
||||||
try message_pb:decode_msg(ReplyBin, auth_reply) of
|
try message_pb:decode_msg(ReplyBin, auth_reply) of
|
||||||
#auth_reply{code = 1, message = Message, repository_url = RepositoryUrl} ->
|
#auth_reply{code = Code, message = Message, repository_url = RepositoryUrl} ->
|
||||||
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
|
case Code of
|
||||||
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
0 ->
|
||||||
%% 主机在后台的授权未通过;此时agent不能推送数据给云端服务器,但是云端服务器可以推送命令给agent
|
lager:debug("[efka_agent] auth failed, message: ~p, repository_url: ~p", [Message, RepositoryUrl]),
|
||||||
%% socket的连接状态需要维持
|
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
||||||
#auth_reply{code = -1, message = Message, repository_url = _} ->
|
1 ->
|
||||||
lager:debug("[efka_agent] auth denied, message: ~p", [Message]),
|
%% 主机在后台的授权未通过;此时agent不能推送数据给云端服务器,但是云端服务器可以推送命令给agent
|
||||||
{noreply, State#state{status = ?STATE_RESTRICTED}};
|
%% socket的连接状态需要维持
|
||||||
#auth_reply{code = -2, message = Message, repository_url = _} ->
|
lager:debug("[efka_agent] auth denied, message: ~p", [Message]),
|
||||||
% 其他类型的错误,需要间隔时间重试
|
{noreply, State#state{status = ?STATE_RESTRICTED}};
|
||||||
efka_logger:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
2 ->
|
||||||
efka_transport:stop(TransportPid),
|
% 其他类型的错误,需要间隔时间重试
|
||||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
|
efka_logger:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
||||||
_ ->
|
efka_transport:stop(TransportPid),
|
||||||
% 其他类型的错误,需要间隔时间重试
|
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
|
||||||
lager:debug("[efka_agent] auth failed, invalid message"),
|
_ ->
|
||||||
efka_transport:stop(TransportPid),
|
% 其他类型的错误,需要间隔时间重试
|
||||||
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}
|
lager:debug("[efka_agent] auth failed, invalid message"),
|
||||||
|
efka_transport:stop(TransportPid),
|
||||||
|
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}
|
||||||
|
end
|
||||||
catch _:Reason ->
|
catch _:Reason ->
|
||||||
% 其他类型的错误,需要间隔时间重试
|
% 其他类型的错误,需要间隔时间重试
|
||||||
lager:debug("[efka_agent] auth decode bin get error: ~p", [Reason]),
|
lager:debug("[efka_agent] auth decode bin get error: ~p", [Reason]),
|
||||||
@ -161,7 +164,7 @@ handle_info({auth_reply, {error, Reason}}, State = #state{transport_pid = Transp
|
|||||||
%% 激活消息
|
%% 激活消息
|
||||||
|
|
||||||
%% TODO
|
%% TODO
|
||||||
handle_info({server_push_message, <<8:8, ActivatePush>>}, State = #state{transport_pid = TransportPid, status = Status}) ->
|
handle_info({server_push_message, <<8:8, ActivatePush/binary>>}, State = #state{transport_pid = TransportPid, status = Status}) ->
|
||||||
#activate_push{auth = Auth} = message_pb:decode_msg(ActivatePush, activate_push),
|
#activate_push{auth = Auth} = message_pb:decode_msg(ActivatePush, activate_push),
|
||||||
case {Auth, Status} of
|
case {Auth, Status} of
|
||||||
{true, ?STATE_ACTIVATED} ->
|
{true, ?STATE_ACTIVATED} ->
|
||||||
@ -176,8 +179,8 @@ handle_info({server_push_message, <<8:8, ActivatePush>>}, State = #state{transpo
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% 收到需要回复的指令
|
%% 收到需要回复的指令
|
||||||
handle_info({server_push_message, PacketId, <<16:8, Directive>>}, State = #state{transport_pid = TransportPid, status = ?STATE_ACTIVATED}) ->
|
handle_info({server_push_message, PacketId, <<16:8, Directive/binary>>}, State = #state{transport_pid = TransportPid, status = ?STATE_ACTIVATED}) ->
|
||||||
#topic_message{topic = Topic, content = Content} = message_pb:decode_msg(Directive, directive),
|
#topic_message{topic = Topic, content = Content} = message_pb:decode_msg(Directive, topic_message),
|
||||||
efka_logger:debug("[efka_agent] get directive with packet_id: ~p, to device_uuid: ~p, content: ~p", [PacketId, Topic, Content]),
|
efka_logger:debug("[efka_agent] get directive with packet_id: ~p, to device_uuid: ~p, content: ~p", [PacketId, Topic, Content]),
|
||||||
%% 消息发送到订阅系统
|
%% 消息发送到订阅系统
|
||||||
case PacketId > 0 of
|
case PacketId > 0 of
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(id_generator_model).
|
-module(id_generator_model).
|
||||||
-author("anlicheng").
|
-author("anlicheng").
|
||||||
|
-include("efka_tables.hrl").
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([create_table/0, next_id/1]).
|
-export([create_table/0, next_id/1]).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user