simple efka
This commit is contained in:
parent
f789e48d51
commit
4eaaed1904
@ -34,8 +34,7 @@
|
||||
|
||||
%% 部署微服务
|
||||
-define(METHOD_DEPLOY, 16#10).
|
||||
-define(METHOD_PRAMAS, 16#11).
|
||||
-define(METHOD_METRICS, 16#12).
|
||||
-define(METHOD_CONFIG, 16#11).
|
||||
|
||||
%% 事件类型
|
||||
-define(EVENT_DEVICE, 16#01).
|
||||
|
||||
@ -259,9 +259,9 @@ handle_info({server_push_message, PacketId, <<?METHOD_DEPLOY:8, DeployBin/binary
|
||||
|
||||
{noreply, State};
|
||||
|
||||
%% 参数项目
|
||||
handle_info({server_push_message, PacketId, <<?METHOD_PRAMAS:8, ParamsBin/binary>>}, State = #state{transport_pid = TransportPid, inflight = Inflight}) ->
|
||||
#service_params{service_id = ServiceId, params = Params, timeout = Timeout} = message_pb:decode_msg(ParamsBin, service_params),
|
||||
%% config.json配置信息
|
||||
handle_info({server_push_message, PacketId, <<?METHOD_CONFIG:8, ParamsBin/binary>>}, State = #state{transport_pid = TransportPid, inflight = Inflight}) ->
|
||||
#service_config{service_id = ServiceId, config_json = ConfigJson, timeout = Timeout} = message_pb:decode_msg(ParamsBin, service_params),
|
||||
|
||||
case efka_micro_service:get_pid(ServiceId) of
|
||||
undefined ->
|
||||
@ -273,7 +273,7 @@ handle_info({server_push_message, PacketId, <<?METHOD_PRAMAS:8, ParamsBin/binary
|
||||
{noreply, State};
|
||||
ServicePid when is_pid(ServicePid) ->
|
||||
Ref = make_ref(),
|
||||
efka_micro_service:push_params(ServicePid, Ref, Params),
|
||||
efka_micro_service:push_config(ServicePid, Ref, ConfigJson),
|
||||
|
||||
%% 处理超时逻辑
|
||||
erlang:start_timer(Timeout * 1000, self(), {request_timeout, Ref}),
|
||||
@ -282,29 +282,6 @@ handle_info({server_push_message, PacketId, <<?METHOD_PRAMAS:8, ParamsBin/binary
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
%% 采集项目
|
||||
handle_info({server_push_message, PacketId, <<?METHOD_METRICS:8, MetricsBin/binary>>}, State = #state{inflight = Inflight}) ->
|
||||
#service_metrics{service_id = ServiceId, metrics = Metrics, timeout = Timeout} = message_pb:decode_msg(MetricsBin, service_metrics),
|
||||
|
||||
case efka_micro_service:get_pid(ServiceId) of
|
||||
undefined ->
|
||||
Reply = #efka_response{
|
||||
code = 0,
|
||||
message = <<"service not run">>
|
||||
},
|
||||
safe_response(PacketId, message_pb:encode_msg(Reply), State),
|
||||
|
||||
{noreply, State};
|
||||
ServicePid when is_pid(ServicePid) ->
|
||||
Ref = make_ref(),
|
||||
efka_micro_service:push_metrics(ServicePid, Ref, Metrics),
|
||||
|
||||
%% 处理超时逻辑
|
||||
erlang:start_timer(Timeout * 1000, self(), {request_timeout, Ref}),
|
||||
|
||||
{noreply, State#state{inflight = maps:put(Ref, PacketId, Inflight)}}
|
||||
end;
|
||||
|
||||
%% 收到来自efka_micro_service的回复
|
||||
handle_info({ems_reply, Ref, EmsReply}, State = #state{inflight = Inflight}) ->
|
||||
case maps:take(Ref, Inflight) of
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user