From d15efa1a96d94169d2f90b2cf08b1e3b4fa32477 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Tue, 20 May 2025 10:58:42 +0800 Subject: [PATCH] fix service --- apps/efka/src/efka_service.erl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/efka/src/efka_service.erl b/apps/efka/src/efka_service.erl index c38712a..c4758a2 100644 --- a/apps/efka/src/efka_service.erl +++ b/apps/efka/src/efka_service.erl @@ -4,6 +4,7 @@ %%% @doc %%% 1. 需要管理服务的整个生命周期,包括: 启动,停止 %%% 2. 需要监控服务的状态,通过port的方式 +%%% 3. 服务的启动和关闭,需要在更高的层级控制 %%% @end %%% Created : 18. 4月 2025 16:50 %%%------------------------------------------------------------------- @@ -15,7 +16,7 @@ %% API -export([start_link/2]). --export([get_name/1, get_pid/1, start_service/1, stop_service/1, attach_channel/2]). +-export([get_name/1, get_pid/1, attach_channel/2]). -export([push_config/3, request_config/1, invoke/3]). -export([metric_data/3, send_event/3]). @@ -47,18 +48,23 @@ get_name(ServiceId) when is_binary(ServiceId) -> get_pid(ServiceId) when is_binary(ServiceId) -> whereis(get_name(ServiceId)). +-spec push_config(Pid :: pid(), Ref :: reference(), ConfigJson :: binary()) -> no_return(). push_config(Pid, Ref, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) -> gen_server:cast(Pid, {push_config, Ref, self(), ConfigJson}). +-spec push_config(Pid :: pid(), Ref :: reference(), Payload :: binary()) -> no_return(). invoke(Pid, Ref, Payload) when is_pid(Pid), is_reference(Ref), is_binary(Payload) -> gen_server:cast(Pid, {invoke, Ref, self(), Payload}). +-spec request_config(Pid :: pid()) -> {ok, Config :: binary()}. request_config(Pid) when is_pid(Pid) -> gen_server:call(Pid, request_config). +-spec metric_data(Pid :: pid(), DeviceUUID :: binary(), Data :: binary()) -> no_return(). metric_data(Pid, DeviceUUID, Data) when is_pid(Pid), is_binary(DeviceUUID), is_binary(Data) -> gen_server:cast(Pid, {metric_data, DeviceUUID, Data}). +-spec send_event(Pid :: pid(), EventType :: integer(), Params :: binary()) -> no_return(). send_event(Pid, EventType, Params) when is_pid(Pid), is_integer(EventType), is_binary(Params) -> gen_server:cast(Pid, {send_event, EventType, Params}). @@ -66,14 +72,6 @@ send_event(Pid, EventType, Params) when is_pid(Pid), is_integer(EventType), is_b attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) -> gen_server:call(Pid, {attach_channel, ChannelPid}). --spec start_service(Pid :: pid()) -> ok | {error, Reason :: binary()}. -start_service(Pid) when is_pid(Pid) -> - gen_server:call(Pid, start_service). - --spec stop_service(Pid :: pid()) -> ok | {error, Reason :: binary()}. -stop_service(Pid) when is_pid(Pid) -> - gen_server:call(Pid, stop_service). - %% @doc Spawns the server and registers the local name (unique) -spec(start_link(Name :: atom(), Service :: binary()) -> {ok, Pid :: pid()} | ignore | {error, Reason :: term()}).