This commit is contained in:
anlicheng 2026-04-21 15:27:16 +08:00
parent d46983f956
commit 835aceb060
7 changed files with 807 additions and 811 deletions

View File

@ -46,6 +46,51 @@
}). }).
-endif. -endif.
-ifndef('AUTHREQUEST_PB_H').
-define('AUTHREQUEST_PB_H', true).
-record('AuthRequest',
{uuid = <<>> :: iodata() | undefined, % = 1, optional
username = <<>> :: iodata() | undefined, % = 2, optional
salt = <<>> :: iodata() | undefined, % = 3, optional
token = <<>> :: iodata() | undefined, % = 4, optional
timestamp = 0 :: integer() | undefined % = 5, optional, 32 bits
}).
-endif.
-ifndef('PUB_PB_H').
-define('PUB_PB_H', true).
-record('Pub',
{topic = <<>> :: iodata() | undefined, % = 1, optional
qos = 0 :: integer() | undefined, % = 2, optional, 32 bits
content = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-ifndef('COMMAND_PB_H').
-define('COMMAND_PB_H', true).
-record('Command',
{command_type = 0 :: integer() | undefined, % = 1, optional, 32 bits
command = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('DATA_PB_H').
-define('DATA_PB_H', true).
-record('Data',
{route_key = <<>> :: iodata() | undefined, % = 1, optional
metric = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('TASKEVENTSTREAM_PB_H').
-define('TASKEVENTSTREAM_PB_H', true).
-record('TaskEventStream',
{task_id = 0 :: integer() | undefined, % = 1, optional, 32 bits
type = <<>> :: iodata() | undefined, % = 2, optional
stream = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-ifndef('CONTAINERREF_PB_H'). -ifndef('CONTAINERREF_PB_H').
-define('CONTAINERREF_PB_H', true). -define('CONTAINERREF_PB_H', true).
-record('ContainerRef', -record('ContainerRef',
@ -230,49 +275,4 @@
}). }).
-endif. -endif.
-ifndef('AUTHREQUEST_PB_H').
-define('AUTHREQUEST_PB_H', true).
-record('AuthRequest',
{uuid = <<>> :: iodata() | undefined, % = 1, optional
username = <<>> :: iodata() | undefined, % = 2, optional
salt = <<>> :: iodata() | undefined, % = 3, optional
token = <<>> :: iodata() | undefined, % = 4, optional
timestamp = 0 :: integer() | undefined % = 5, optional, 32 bits
}).
-endif.
-ifndef('PUB_PB_H').
-define('PUB_PB_H', true).
-record('Pub',
{topic = <<>> :: iodata() | undefined, % = 1, optional
qos = 0 :: integer() | undefined, % = 2, optional, 32 bits
content = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-ifndef('COMMAND_PB_H').
-define('COMMAND_PB_H', true).
-record('Command',
{command_type = 0 :: integer() | undefined, % = 1, optional, 32 bits
command = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('DATA_PB_H').
-define('DATA_PB_H', true).
-record('Data',
{route_key = <<>> :: iodata() | undefined, % = 1, optional
metric = <<>> :: iodata() | undefined % = 2, optional
}).
-endif.
-ifndef('TASKEVENTSTREAM_PB_H').
-define('TASKEVENTSTREAM_PB_H', true).
-record('TaskEventStream',
{task_id = 0 :: integer() | undefined, % = 1, optional, 32 bits
type = <<>> :: iodata() | undefined, % = 2, optional
stream = <<>> :: iodata() | undefined % = 3, optional
}).
-endif.
-endif. -endif.

View File

@ -10,6 +10,7 @@
{gpb_opts, [ {gpb_opts, [
{i, "proto"}, % proto 文件路径 {i, "proto"}, % proto 文件路径
{src_dirs, ["proto"]}, % 源码目录(必须) {src_dirs, ["proto"]}, % 源码目录(必须)
{f, ["message.proto", "service.proto"]},
recursive, % 递归查找 proto 文件 recursive, % 递归查找 proto 文件
{module_name_suffix, "_pb"}, % 生成模块后缀 {module_name_suffix, "_pb"}, % 生成模块后缀
{o_erl, "src/protobuf"}, % .erl 输出目录 {o_erl, "src/protobuf"}, % .erl 输出目录

View File

@ -70,8 +70,8 @@ handle_info({'DOWN', _Ref, process, TaskPid, Reason}, State = #state{task_map =
logger:debug("[docker_deploy_manager] task_id: ~p, exit normal", [TaskId]); logger:debug("[docker_deploy_manager] task_id: ~p, exit normal", [TaskId]);
Error0 -> Error0 ->
Error = iolist_to_binary(io_lib:format("~p", [Error0])), Error = iolist_to_binary(io_lib:format("~p", [Error0])),
efka_task_reporter:stream(TaskId, <<"error">>, <<"任务失败: "/utf8, Error/binary>>), docker_task_reporter:stream(TaskId, <<"error">>, <<"任务失败: "/utf8, Error/binary>>),
efka_task_reporter:close(TaskId, <<"task exited">>), docker_task_reporter:close(TaskId, <<"task exited">>),
logger:notice("[docker_deploy_manager] task_id: ~p, exit with error: ~p", [TaskId, Error]) logger:notice("[docker_deploy_manager] task_id: ~p, exit with error: ~p", [TaskId, Error])
end, end,
{noreply, State#state{task_map = NTaskMap}} {noreply, State#state{task_map = NTaskMap}}

View File

@ -56,21 +56,21 @@ deploy(TaskId, ContainerDir, Params = #'ContainerDeployParams'{
report_task_event(TaskId, <<"info">>, <<"容器创建成功: "/utf8, ShortContainerId/binary>>), report_task_event(TaskId, <<"info">>, <<"容器创建成功: "/utf8, ShortContainerId/binary>>),
report_task_event(TaskId, <<"info">>, <<"任务完成"/utf8>>), report_task_event(TaskId, <<"info">>, <<"任务完成"/utf8>>),
write_task_summary(TaskId, <<"success">>, ContainerName, Image, ContainerId), write_task_summary(TaskId, <<"success">>, ContainerName, Image, ContainerId),
efka_task_reporter:close(TaskId, ?TASK_SUCCESS) docker_task_reporter:close(TaskId, ?TASK_SUCCESS)
catch catch
throw:{deploy_error, Reason} -> throw:{deploy_error, Reason} ->
report_task_event(TaskId, <<"error">>, Reason), report_task_event(TaskId, <<"error">>, Reason),
report_task_event(TaskId, <<"error">>, <<"任务失败"/utf8>>), report_task_event(TaskId, <<"error">>, <<"任务失败"/utf8>>),
write_task_summary(TaskId, <<"fail">>, ContainerName, Image0, undefined), write_task_summary(TaskId, <<"fail">>, ContainerName, Image0, undefined),
write_task_failure_reason(TaskId, Reason), write_task_failure_reason(TaskId, Reason),
efka_task_reporter:close(TaskId, ?TASK_FAIL); docker_task_reporter:close(TaskId, ?TASK_FAIL);
Class:Reason:Stacktrace -> Class:Reason:Stacktrace ->
Error = iolist_to_binary(io_lib:format("deploy crashed: ~p:~p ~p", [Class, Reason, Stacktrace])), Error = iolist_to_binary(io_lib:format("deploy crashed: ~p:~p ~p", [Class, Reason, Stacktrace])),
report_task_event(TaskId, <<"error">>, Error), report_task_event(TaskId, <<"error">>, Error),
report_task_event(TaskId, <<"error">>, <<"任务失败"/utf8>>), report_task_event(TaskId, <<"error">>, <<"任务失败"/utf8>>),
write_task_summary(TaskId, <<"fail">>, ContainerName, Image0, undefined), write_task_summary(TaskId, <<"fail">>, ContainerName, Image0, undefined),
write_task_failure_reason(TaskId, Error), write_task_failure_reason(TaskId, Error),
efka_task_reporter:close(TaskId, ?TASK_FAIL) docker_task_reporter:close(TaskId, ?TASK_FAIL)
end. end.
-spec normalize_image(binary()) -> binary(). -spec normalize_image(binary()) -> binary().
@ -85,7 +85,7 @@ normalize_image(Image) when is_binary(Image) ->
-spec report_task_event(TaskId :: integer(), Level :: binary(), Msg :: binary()) -> ok. -spec report_task_event(TaskId :: integer(), Level :: binary(), Msg :: binary()) -> ok.
report_task_event(TaskId, Level, Msg) when is_integer(TaskId), is_binary(Level), is_binary(Msg) -> report_task_event(TaskId, Level, Msg) when is_integer(TaskId), is_binary(Level), is_binary(Msg) ->
efka_task_reporter:stream(TaskId, Level, Msg). docker_task_reporter:stream(TaskId, Level, Msg).
-spec write_task_summary(integer(), binary(), binary(), binary(), undefined | binary()) -> ok. -spec write_task_summary(integer(), binary(), binary(), binary(), undefined | binary()) -> ok.
write_task_summary(TaskId, Status, ContainerName, Image, ContainerId) write_task_summary(TaskId, Status, ContainerName, Image, ContainerId)

View File

@ -6,7 +6,7 @@
%%% @end %%% @end
%%% Created : 20. 4 2026 %%% Created : 20. 4 2026
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(efka_task_reporter). -module(docker_task_reporter).
-author("anlicheng"). -author("anlicheng").
-behaviour(gen_server). -behaviour(gen_server).

View File

@ -92,12 +92,12 @@ init([]) ->
}, },
#{ #{
id => 'efka_task_reporter', id => 'docker_task_reporter',
start => {'efka_task_reporter', start_link, []}, start => {'docker_task_reporter', start_link, []},
restart => permanent, restart => permanent,
shutdown => 2000, shutdown => 2000,
type => worker, type => worker,
modules => ['efka_task_reporter'] modules => ['docker_task_reporter']
}, },
#{ #{

File diff suppressed because it is too large Load Diff