Current section

Files

Jump to
glixir src glixir@libcluster.erl
Raw

src/glixir@libcluster.erl

-module(glixir@libcluster).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glixir/libcluster.gleam").
-export([connected_nodes/0, node_name/0, start_clustering_dns/3, start_clustering_fly/1, start_clustering_local/1, connected_node_names/0, current_node_name/0, is_clustered/0]).
-export_type([cluster_strategy/0, cluster_start_result/0, cluster_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type cluster_strategy() :: d_n_s_poll | gossip | kubernetes | e_p_m_d | e_c2.
-type cluster_start_result() :: {cluster_start_ok, gleam@erlang@process:pid_()} |
{cluster_start_error, binary()}.
-type cluster_error() :: {start_error, binary()} | {config_error, binary()}.
-file("src/glixir/libcluster.gleam", 43).
-spec connected_nodes() -> list(gleam@erlang@atom:atom_()).
connected_nodes() ->
'Elixir.Glixir.LibCluster':connected_nodes().
-file("src/glixir/libcluster.gleam", 46).
-spec node_name() -> gleam@erlang@atom:atom_().
node_name() ->
'Elixir.Glixir.LibCluster':node_name().
-file("src/glixir/libcluster.gleam", 51).
?DOC(" Start clustering with DNS poll (most common for production)\n").
-spec start_clustering_dns(binary(), binary(), integer()) -> {ok,
gleam@erlang@process:pid_()} |
{error, cluster_error()}.
start_clustering_dns(App_name, Query, Polling_interval) ->
logging:log(
info,
<<"[LibCluster] Starting DNS clustering for: "/utf8, App_name/binary>>
),
case 'Elixir.Glixir.LibCluster':start_link(
App_name,
<<"dns_poll"/utf8>>,
Polling_interval,
Query
) of
{cluster_start_ok, Pid} ->
logging:log(
info,
<<"[LibCluster] Clustering started successfully"/utf8>>
),
{ok, Pid};
{cluster_start_error, Reason} ->
logging:log(
error,
<<"[LibCluster] Failed to start: "/utf8, Reason/binary>>
),
{error, {start_error, Reason}}
end.
-file("src/glixir/libcluster.gleam", 74).
?DOC(" Start clustering for Fly.io (uses DNS polling automatically)\n").
-spec start_clustering_fly(binary()) -> {ok, gleam@erlang@process:pid_()} |
{error, cluster_error()}.
start_clustering_fly(App_name) ->
logging:log(info, <<"[LibCluster] Starting Fly.io clustering"/utf8>>),
case 'Elixir.Glixir.LibCluster':start_link_fly(App_name) of
{cluster_start_ok, Pid} ->
logging:log(
info,
<<"[LibCluster] Fly.io clustering started for: "/utf8,
App_name/binary>>
),
{ok, Pid};
{cluster_start_error, Reason} ->
{error, {start_error, Reason}}
end.
-file("src/glixir/libcluster.gleam", 90).
?DOC(" Start clustering for local development (uses Gossip)\n").
-spec start_clustering_local(binary()) -> {ok, gleam@erlang@process:pid_()} |
{error, cluster_error()}.
start_clustering_local(App_name) ->
logging:log(info, <<"[LibCluster] Starting local clustering"/utf8>>),
case 'Elixir.Glixir.LibCluster':start_link_local(App_name) of
{cluster_start_ok, Pid} ->
logging:log(info, <<"[LibCluster] Local clustering started"/utf8>>),
{ok, Pid};
{cluster_start_error, Reason} ->
{error, {start_error, Reason}}
end.
-file("src/glixir/libcluster.gleam", 103).
?DOC(" Get list of connected node names as strings\n").
-spec connected_node_names() -> list(binary()).
connected_node_names() ->
_pipe = 'Elixir.Glixir.LibCluster':connected_nodes(),
gleam@list:map(_pipe, fun erlang:atom_to_binary/1).
-file("src/glixir/libcluster.gleam", 109).
?DOC(" Get current node name as string\n").
-spec current_node_name() -> binary().
current_node_name() ->
_pipe = 'Elixir.Glixir.LibCluster':node_name(),
erlang:atom_to_binary(_pipe).
-file("src/glixir/libcluster.gleam", 115).
?DOC(" Check if clustering is active (has connected nodes)\n").
-spec is_clustered() -> boolean().
is_clustered() ->
erlang:length('Elixir.Glixir.LibCluster':connected_nodes()) > 0.