From 86b44a84ebfbd0ad30258714e326e8b25e23c87b Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 30 Apr 2025 14:06:03 +0800 Subject: [PATCH] fix --- apps/efka/src/efka_micro_service.erl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/efka/src/efka_micro_service.erl b/apps/efka/src/efka_micro_service.erl index fb5426f..385bdec 100644 --- a/apps/efka/src/efka_micro_service.erl +++ b/apps/efka/src/efka_micro_service.erl @@ -15,7 +15,7 @@ %% API -export([start_link/2]). --export([get_name/1, start_service/1, stop_service/1, attach_channel/2]). +-export([get_name/1, get_pid/1, start_service/1, stop_service/1, attach_channel/2]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). @@ -34,9 +34,13 @@ %%% API %%%=================================================================== --spec get_name(ServerId :: binary()) -> atom(). -get_name(ServerId) when is_binary(ServerId) -> - list_to_atom("efka_service:" ++ binary_to_list(ServerId)). +-spec get_name(ServiceId :: binary()) -> atom(). +get_name(ServiceId) when is_binary(ServiceId) -> + list_to_atom("efka_service:" ++ binary_to_list(ServiceId)). + +-spec get_pid(ServiceId :: binary()) -> undefined | pid(). +get_pid(ServiceId) when is_binary(ServiceId) -> + whereis(get_name(ServiceId)). -spec attach_channel(pid(), pid()) -> ok | {error, Reason :: binary()}. attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) -> @@ -146,13 +150,12 @@ handle_info({timeout, _, boot_service}, State = #state{service = #micro_service{ end; handle_info({Port, {data, Data}}, State = #state{port = Port, service = Service}) -> - lager:debug("[efka_micro_service] service_id: ~p, port exit with code: ~p", [Service#micro_service.service_id, Data]), + lager:debug("[efka_micro_service] service_id: ~p, port data: ~p", [Service#micro_service.service_id, Data]), {noreply, State}; %% 处理port的消息 handle_info({Port, {exit_status, Code}}, State = #state{port = Port, service = Service}) -> lager:debug("[efka_micro_service] service_id: ~p, port exit with code: ~p", [Service#micro_service.service_id, Code]), - %erlang:start_timer(5000, self(), boot_service), - %erlang:port_close(Port), + erlang:start_timer(5000, self(), boot_service), {noreply, State#state{port = undefined}}.