fix
This commit is contained in:
parent
5ed60b4f66
commit
86b44a84eb
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/2]).
|
-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
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
||||||
@ -34,9 +34,13 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
-spec get_name(ServerId :: binary()) -> atom().
|
-spec get_name(ServiceId :: binary()) -> atom().
|
||||||
get_name(ServerId) when is_binary(ServerId) ->
|
get_name(ServiceId) when is_binary(ServiceId) ->
|
||||||
list_to_atom("efka_service:" ++ binary_to_list(ServerId)).
|
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()}.
|
-spec attach_channel(pid(), pid()) -> ok | {error, Reason :: binary()}.
|
||||||
attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) ->
|
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;
|
end;
|
||||||
|
|
||||||
handle_info({Port, {data, Data}}, State = #state{port = Port, service = Service}) ->
|
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};
|
{noreply, State};
|
||||||
%% 处理port的消息
|
%% 处理port的消息
|
||||||
handle_info({Port, {exit_status, Code}}, State = #state{port = Port, service = Service}) ->
|
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]),
|
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:start_timer(5000, self(), boot_service),
|
||||||
%erlang:port_close(Port),
|
|
||||||
|
|
||||||
{noreply, State#state{port = undefined}}.
|
{noreply, State#state{port = undefined}}.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user