fix
This commit is contained in:
parent
efb128ee28
commit
901d91e83e
@ -39,8 +39,6 @@ start_monitor(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(Con
|
|||||||
%}
|
%}
|
||||||
-spec deploy(TaskId :: integer(), ContainerDir :: string(), Config :: map()) -> no_return().
|
-spec deploy(TaskId :: integer(), ContainerDir :: string(), Config :: map()) -> no_return().
|
||||||
deploy(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(ContainerDir), is_map(Config) ->
|
deploy(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(ContainerDir), is_map(Config) ->
|
||||||
Q = queue:new(),
|
|
||||||
|
|
||||||
%% 尝试拉取镜像
|
%% 尝试拉取镜像
|
||||||
ContainerName = maps:get(<<"container_name">>, Config),
|
ContainerName = maps:get(<<"container_name">>, Config),
|
||||||
|
|
||||||
@ -73,9 +71,9 @@ deploy(TaskId, ContainerDir, Config) when is_integer(TaskId), is_list(ContainerD
|
|||||||
efka_remote_agent:task_event_stream(TaskId, <<"info">>, Msg4),
|
efka_remote_agent:task_event_stream(TaskId, <<"info">>, Msg4),
|
||||||
efka_logger:write(format_log(TaskId, <<"info">>, Msg4)),
|
efka_logger:write(format_log(TaskId, <<"info">>, Msg4)),
|
||||||
CB = fun
|
CB = fun
|
||||||
({message, Msg}) ->
|
({message, M}) ->
|
||||||
efka_remote_agent:task_event_stream(TaskId, <<"info">>, Msg),
|
efka_remote_agent:task_event_stream(TaskId, <<"info">>, M),
|
||||||
efka_logger:write(format_log(TaskId, <<"info">>, Msg));
|
efka_logger:write(format_log(TaskId, <<"info">>, M));
|
||||||
({error, Error}) ->
|
({error, Error}) ->
|
||||||
efka_remote_agent:task_event_stream(TaskId, <<"error">>, Error),
|
efka_remote_agent:task_event_stream(TaskId, <<"error">>, Error),
|
||||||
efka_logger:write(format_log(TaskId, <<"error">>, Error))
|
efka_logger:write(format_log(TaskId, <<"error">>, Error))
|
||||||
|
|||||||
@ -1,122 +0,0 @@
|
|||||||
%%%-------------------------------------------------------------------
|
|
||||||
%%% @author anlicheng
|
|
||||||
%%% @copyright (C) 2025, <COMPANY>
|
|
||||||
%%% @doc
|
|
||||||
%%%
|
|
||||||
%%% @end
|
|
||||||
%%% Created : 13. 8月 2025 17:01
|
|
||||||
%%%-------------------------------------------------------------------
|
|
||||||
-module(task_log_model).
|
|
||||||
-author("anlicheng").
|
|
||||||
-include("efka_tables.hrl").
|
|
||||||
|
|
||||||
-behaviour(gen_server).
|
|
||||||
|
|
||||||
%% API
|
|
||||||
-export([start_link/0]).
|
|
||||||
-export([insert/2, get_logs/1]).
|
|
||||||
|
|
||||||
%% gen_server callbacks
|
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
|
||||||
|
|
||||||
-define(SERVER, ?MODULE).
|
|
||||||
-define(TAB, task_log).
|
|
||||||
|
|
||||||
-record(state, {
|
|
||||||
|
|
||||||
}).
|
|
||||||
|
|
||||||
%%%===================================================================
|
|
||||||
%%% API
|
|
||||||
%%%===================================================================
|
|
||||||
-spec insert(TaskId :: integer(), Logs :: [binary()]) -> ok | {error, Reason :: term()}.
|
|
||||||
insert(TaskId, Logs) when is_integer(TaskId), is_list(Logs) ->
|
|
||||||
TaskLog = #task_log{task_id = TaskId, logs = Logs},
|
|
||||||
gen_server:call(?SERVER, {insert, TaskLog}).
|
|
||||||
|
|
||||||
-spec get_logs(TaskId :: integer()) -> Logs :: [binary()].
|
|
||||||
get_logs(TaskId) when is_integer(TaskId) ->
|
|
||||||
gen_server:call(?SERVER, {get_logs, TaskId}).
|
|
||||||
|
|
||||||
%% @doc Spawns the server and registers the local name (unique)
|
|
||||||
-spec(start_link() ->
|
|
||||||
{ok, Pid :: pid()} | ignore | {error, Reason :: term()}).
|
|
||||||
start_link() ->
|
|
||||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
|
|
||||||
|
|
||||||
%%%===================================================================
|
|
||||||
%%% gen_server callbacks
|
|
||||||
%%%===================================================================
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc Initializes the server
|
|
||||||
-spec(init(Args :: term()) ->
|
|
||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
|
||||||
{stop, Reason :: term()} | ignore).
|
|
||||||
init([]) ->
|
|
||||||
{ok, DetsDir} = application:get_env(efka, dets_dir),
|
|
||||||
File = DetsDir ++ "task_log.dets",
|
|
||||||
{ok, ?TAB} = dets:open_file(?TAB, [{file, File}, {type, set}, {keypos, 2}]),
|
|
||||||
{ok, #state{}}.
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc Handling call messages
|
|
||||||
-spec(handle_call(Request :: term(), From :: {pid(), Tag :: term()},
|
|
||||||
State :: #state{}) ->
|
|
||||||
{reply, Reply :: term(), NewState :: #state{}} |
|
|
||||||
{reply, Reply :: term(), NewState :: #state{}, timeout() | hibernate} |
|
|
||||||
{noreply, NewState :: #state{}} |
|
|
||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
|
||||||
{stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
|
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
|
||||||
handle_call({insert, TaskLog}, _From, State = #state{}) ->
|
|
||||||
ok = dets:insert(?TAB, TaskLog),
|
|
||||||
{reply, ok, State};
|
|
||||||
handle_call({get_logs, TaskId}, _From, State = #state{}) ->
|
|
||||||
Reply = case dets:lookup(?TAB, TaskId) of
|
|
||||||
[] ->
|
|
||||||
[];
|
|
||||||
[#task_log{logs = Logs}|_] ->
|
|
||||||
Logs
|
|
||||||
end,
|
|
||||||
{reply, Reply, State}.
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc Handling cast messages
|
|
||||||
-spec(handle_cast(Request :: term(), State :: #state{}) ->
|
|
||||||
{noreply, NewState :: #state{}} |
|
|
||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
|
||||||
handle_cast(_Request, State = #state{}) ->
|
|
||||||
{noreply, State}.
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc Handling all non call/cast messages
|
|
||||||
-spec(handle_info(Info :: timeout() | term(), State :: #state{}) ->
|
|
||||||
{noreply, NewState :: #state{}} |
|
|
||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
|
||||||
handle_info(_Info, State = #state{}) ->
|
|
||||||
{noreply, State}.
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc This function is called by a gen_server when it is about to
|
|
||||||
%% terminate. It should be the opposite of Module:init/1 and do any
|
|
||||||
%% necessary cleaning up. When it returns, the gen_server terminates
|
|
||||||
%% with Reason. The return value is ignored.
|
|
||||||
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
|
|
||||||
State :: #state{}) -> term()).
|
|
||||||
terminate(_Reason, _State = #state{}) ->
|
|
||||||
ok.
|
|
||||||
|
|
||||||
%% @private
|
|
||||||
%% @doc Convert process state when code is changed
|
|
||||||
-spec(code_change(OldVsn :: term() | {down, term()}, State :: #state{},
|
|
||||||
Extra :: term()) ->
|
|
||||||
{ok, NewState :: #state{}} | {error, Reason :: term()}).
|
|
||||||
code_change(_OldVsn, State = #state{}, _Extra) ->
|
|
||||||
{ok, State}.
|
|
||||||
|
|
||||||
%%%===================================================================
|
|
||||||
%%% Internal functions
|
|
||||||
%%%===================================================================
|
|
||||||
Loading…
x
Reference in New Issue
Block a user