Улучшения в кластере. Кластер формируется динамически, без единой точки отказа (каждая нода подключается ко всем трём через connect_nodes/0)

This commit is contained in:
2026-04-24 20:32:37 +03:00
parent 48d8ba7a2c
commit 6bb29174a5
4 changed files with 78 additions and 134 deletions

View File

@@ -12,6 +12,7 @@ start(_StartType, _StartArgs) ->
{ok, Pid} ->
ok = infra_mnesia:init_tables(),
ok = infra_mnesia:wait_for_tables(),
connect_nodes(),
start_http(),
start_admin_http(),
% Запускаем сборщик метрик Prometheus
@@ -126,4 +127,18 @@ start_admin_http() ->
env => #{dispatch => AdminWsDispatch}
}),
io:format("WebSocket started on ports 8081 (user) and 8446 (admin)~n").
io:format("WebSocket started on ports 8081 (user) and 8446 (admin)~n").
connect_nodes() ->
case os:getenv("JOIN_NODES") of
false -> ok;
NodesStr ->
Nodes = [list_to_atom(string:trim(N)) || N <- string:tokens(NodesStr, ",")],
lists:foreach(fun(Node) ->
case net_kernel:connect_node(Node) of
true -> io:format("Connected to ~s~n", [Node]);
false -> io:format("ERROR: Failed to connect to ~s~n", [Node]);
ignored -> ok
end
end, Nodes)
end.