Настройка репликации. Часть 1 #14

This commit is contained in:
2026-05-03 14:55:57 +03:00
parent 4fdf380f15
commit 3d61830f1c
6 changed files with 137 additions and 58 deletions
+11 -5
View File
@@ -8,15 +8,21 @@ start(_StartType, _StartArgs) ->
application:ensure_all_started(cowboy),
case infra_sup:start_link() of
{ok, Pid} ->
% Чтение extra_db_nodes из переменной окружения (если задана)
case os:getenv("MNESIA_EXTRA_DB_NODES") of
false -> ok;
NodesStr ->
Nodes = [list_to_atom(N) || N <- string:tokens(NodesStr, ",")],
application:set_env(eventhub, extra_db_nodes, Nodes)
end,
ok = infra_mnesia:init_tables(),
ok = infra_mnesia:wait_for_tables(),
% Включаем авто‑обнаружение только в режиме remote/swarm
ClusterMode = os:getenv("CLUSTER_MODE", "local"),
if ClusterMode =:= "swarm" orelse ClusterMode =:= "remote" ->
spawn(fun cluster_discovery:discover/0);
true ->
% Локальный запуск – подключаемся по старинке или вообще не подключаемся
ok
case ClusterMode of
"swarm" -> cluster_discovery:discover_and_replicate();
"remote" -> cluster_discovery:discover_and_replicate();
_ -> ok
end,
start_http(), % Пользовательский API (8080)
start_admin_http(), % Административный API (8445)