fix service
This commit is contained in:
parent
58efa14707
commit
18967afb7a
@ -99,17 +99,7 @@ init([ServiceId]) ->
|
||||
ignore;
|
||||
{ok, #service{root_dir = RootDir}} ->
|
||||
%% 尝试更新微服务的配置信息
|
||||
case efka_agent:request_service_config(self(), ServiceId) of
|
||||
{ok, Ref} ->
|
||||
case efka_agent:await_reply(Ref, 5000) of
|
||||
{ok, ConfigJson} ->
|
||||
service_model:set_config(ServiceId, ConfigJson);
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_service] request_config get error: ~p", [Reason])
|
||||
end;
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_service] request_config get error: ~p", [Reason])
|
||||
end,
|
||||
try_update_config(ServiceId),
|
||||
|
||||
%% 第一次启动,要求必须成功;只有第一次启动成功,后续的重启逻辑才有意义
|
||||
case efka_manifest:new(RootDir) of
|
||||
@ -300,4 +290,18 @@ trigger_callback(Ref, Callbacks) ->
|
||||
{Fun, NCallbacks} ->
|
||||
catch Fun(),
|
||||
NCallbacks
|
||||
end.
|
||||
end.
|
||||
|
||||
-spec try_update_config(ServiceId :: binary()) -> no_return().
|
||||
try_update_config(ServiceId) when is_binary(ServiceId) ->
|
||||
case efka_agent:request_service_config(self(), ServiceId) of
|
||||
{ok, Ref} ->
|
||||
case efka_agent:await_reply(Ref, 5000) of
|
||||
{ok, ConfigJson} ->
|
||||
service_model:set_config(ServiceId, ConfigJson);
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_service] request_config get error: ~p", [Reason])
|
||||
end;
|
||||
{error, Reason} ->
|
||||
lager:debug("[efka_service] request_config get error: ~p", [Reason])
|
||||
end.
|
||||
|
||||
@ -43,6 +43,9 @@ init([]) ->
|
||||
SupFlags = #{strategy => one_for_one, intensity => 1000, period => 3600},
|
||||
%% 简化逻辑,只启动需要运行的微服务
|
||||
{ok, Services} = service_model:get_running_services(),
|
||||
ServiceIds = lists:map(fun(#service{service_id = ServiceId}) -> ServiceId end, Services),
|
||||
lager:debug("[efka_service_sup] will start services: ~p", [ServiceIds]),
|
||||
|
||||
Specs = lists:map(fun(ServiceId) -> child_spec(ServiceId) end, Services),
|
||||
|
||||
{ok, {SupFlags, Specs}}.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user