This commit is contained in:
anlicheng 2025-04-30 14:06:03 +08:00
parent 5ed60b4f66
commit 86b44a84eb

View File

@ -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}}.