fix
This commit is contained in:
parent
1855d632c5
commit
e5cf3222df
@ -213,10 +213,10 @@ handle_info({auth_reply, {ok, ReplyBin}}, State = #state{status = ?STATE_AUTH, t
|
|||||||
lager:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
lager:debug("[efka_agent] auth failed, message: ~p", [Message]),
|
||||||
|
|
||||||
%% 上传缓冲区里面的所有数据
|
%% 上传缓冲区里面的所有数据
|
||||||
CacheItems = micro_cache_model:get_all_cache(),
|
CacheItems = cache_model:get_all_cache(),
|
||||||
lists:foreach(fun(#micro_cache{id = Id, method = Method, data = Packet}) ->
|
lists:foreach(fun(#micro_cache{id = Id, method = Method, data = Packet}) ->
|
||||||
efka_transport:send(TransportPid, Method, Packet),
|
efka_transport:send(TransportPid, Method, Packet),
|
||||||
micro_cache_model:delete(Id)
|
cache_model:delete(Id)
|
||||||
end, CacheItems),
|
end, CacheItems),
|
||||||
|
|
||||||
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
{noreply, State#state{status = ?STATE_ACTIVATED}};
|
||||||
@ -384,4 +384,4 @@ safe_response(_PacketId, _Reply, #state{}) ->
|
|||||||
safe_send(Method, Packet, #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) when is_pid(TransportPid) ->
|
safe_send(Method, Packet, #state{status = ?STATE_ACTIVATED, transport_pid = TransportPid}) when is_pid(TransportPid) ->
|
||||||
efka_transport:send(TransportPid, Method, Packet);
|
efka_transport:send(TransportPid, Method, Packet);
|
||||||
safe_send(Method, Packet, #state{}) ->
|
safe_send(Method, Packet, #state{}) ->
|
||||||
ok = micro_cache_model:insert(Method, Packet).
|
ok = cache_model:insert(Method, Packet).
|
||||||
@ -34,6 +34,6 @@ start_mnesia() ->
|
|||||||
lager:debug("[efka_app] tables: ~p", [Tables]),
|
lager:debug("[efka_app] tables: ~p", [Tables]),
|
||||||
%% 创建数据库表
|
%% 创建数据库表
|
||||||
not lists:member(id_generator, Tables) andalso id_generator_model:create_table(),
|
not lists:member(id_generator, Tables) andalso id_generator_model:create_table(),
|
||||||
not lists:member(micro_service, Tables) andalso micro_service_model:create_table(),
|
not lists:member(micro_service, Tables) andalso service_model:create_table(),
|
||||||
not lists:member(micro_data, Tables) andalso micro_data_model:create_table(),
|
not lists:member(micro_data, Tables) andalso micro_data_model:create_table(),
|
||||||
ok.
|
ok.
|
||||||
@ -95,7 +95,7 @@ handle_cast(deploy, State = #state{task_id = TaskId, root_dir = RootDir, service
|
|||||||
%% 创建lock文件
|
%% 创建lock文件
|
||||||
touch_lock(ServiceRootDir, TarUrl),
|
touch_lock(ServiceRootDir, TarUrl),
|
||||||
%% 更新数据
|
%% 更新数据
|
||||||
ok = micro_service_model:insert(#micro_service{
|
ok = service_model:insert(#micro_service{
|
||||||
service_id = ServiceId,
|
service_id = ServiceId,
|
||||||
tar_url = TarUrl,
|
tar_url = TarUrl,
|
||||||
%% 工作目录
|
%% 工作目录
|
||||||
|
|||||||
@ -110,7 +110,7 @@ start_link(Name, ServiceId) when is_atom(Name), is_binary(ServiceId) ->
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([ServiceId]) ->
|
init([ServiceId]) ->
|
||||||
case micro_service_model:get_service(ServiceId) of
|
case service_model:get_service(ServiceId) of
|
||||||
error ->
|
error ->
|
||||||
lager:notice("[efka_micro_service] service_id: ~p, not found", [ServiceId]),
|
lager:notice("[efka_micro_service] service_id: ~p, not found", [ServiceId]),
|
||||||
ignore;
|
ignore;
|
||||||
@ -151,7 +151,7 @@ init0(#micro_service{service_id = ServiceId, status = 0}, Manifest) ->
|
|||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
%% 绑定channel
|
%% 绑定channel
|
||||||
handle_call({attach_channel, ChannelPid}, _From, State = #state{channel_pid = OldChannelPid, service_id = ServiceId}) ->
|
handle_call({attach_channel, ChannelPid}, _From, State = #state{channel_pid = OldChannelPid, service_id = ServiceId}) ->
|
||||||
Status = micro_service_model:get_status(ServiceId),
|
Status = service_model:get_status(ServiceId),
|
||||||
case {Status, is_pid(OldChannelPid) andalso is_process_alive(OldChannelPid)} of
|
case {Status, is_pid(OldChannelPid) andalso is_process_alive(OldChannelPid)} of
|
||||||
{1, false} ->
|
{1, false} ->
|
||||||
erlang:monitor(process, ChannelPid),
|
erlang:monitor(process, ChannelPid),
|
||||||
@ -164,7 +164,7 @@ handle_call({attach_channel, ChannelPid}, _From, State = #state{channel_pid = Ol
|
|||||||
|
|
||||||
%% 请求参数项 done
|
%% 请求参数项 done
|
||||||
handle_call(request_config, _From, State = #state{service_id = ServiceId, running_status = ?STATUS_RUNNING}) ->
|
handle_call(request_config, _From, State = #state{service_id = ServiceId, running_status = ?STATUS_RUNNING}) ->
|
||||||
Params = micro_service_model:get_params(ServiceId),
|
Params = service_model:get_params(ServiceId),
|
||||||
{reply, {ok, Params}, State};
|
{reply, {ok, Params}, State};
|
||||||
|
|
||||||
%% 启动服务: 当前服务如果正常运行,则不允许重启
|
%% 启动服务: 当前服务如果正常运行,则不允许重启
|
||||||
@ -177,7 +177,7 @@ handle_call(start_service, _From, State = #state{running_status = ?STATUS_STOPPE
|
|||||||
{os_pid, OSPid} = erlang:port_info(Port, os_pid),
|
{os_pid, OSPid} = erlang:port_info(Port, os_pid),
|
||||||
lager:debug("start_service port: ~p, os_pid: ~p", [Port, OSPid]),
|
lager:debug("start_service port: ~p, os_pid: ~p", [Port, OSPid]),
|
||||||
%% 更新数据库状态
|
%% 更新数据库状态
|
||||||
ok = micro_service_model:change_status(ServiceId, 1),
|
ok = service_model:change_status(ServiceId, 1),
|
||||||
{reply, ok, State#state{running_status = ?STATUS_RUNNING, port = Port, os_pid = OSPid}};
|
{reply, ok, State#state{running_status = ?STATUS_RUNNING, port = Port, os_pid = OSPid}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
%% 启动失败不能更新数据库里面的状态
|
%% 启动失败不能更新数据库里面的状态
|
||||||
@ -195,7 +195,7 @@ handle_call(stop_service, _From, State = #state{running_status = ?STATUS_RUNNING
|
|||||||
|
|
||||||
erlang:is_port(Port) andalso erlang:port_close(Port),
|
erlang:is_port(Port) andalso erlang:port_close(Port),
|
||||||
lager:debug("port: ~p, os_pid: ~p, will closed", [Port, OSPid]),
|
lager:debug("port: ~p, os_pid: ~p, will closed", [Port, OSPid]),
|
||||||
ok = micro_service_model:change_status(ServiceId, 0),
|
ok = service_model:change_status(ServiceId, 0),
|
||||||
|
|
||||||
{reply, ok, State#state{port = undefined, os_pid = undefined, running_status = ?STATUS_STOPPED}};
|
{reply, ok, State#state{port = undefined, os_pid = undefined, running_status = ?STATUS_STOPPED}};
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ handle_cast(_Request, State = #state{}) ->
|
|||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
%% 重启服务
|
%% 重启服务
|
||||||
handle_info({timeout, _, reboot_service}, State = #state{service_id = ServiceId, manifest = Manifest}) ->
|
handle_info({timeout, _, reboot_service}, State = #state{service_id = ServiceId, manifest = Manifest}) ->
|
||||||
case micro_service_model:get_status(ServiceId) of
|
case service_model:get_status(ServiceId) of
|
||||||
0 ->
|
0 ->
|
||||||
lager:debug("[efka_micro_service] service_id: ~p, is stopped, ignore boot_service", [ServiceId]),
|
lager:debug("[efka_micro_service] service_id: ~p, is stopped, ignore boot_service", [ServiceId]),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user