fix service

This commit is contained in:
anlicheng 2025-05-21 14:51:11 +08:00
parent 58efa14707
commit 18967afb7a
2 changed files with 19 additions and 12 deletions

View File

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

View File

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