Reputation: 45
I have a phoenix project that must be AP in the CAP theorem so I need to detect network partitions and ensure my node connects to at least one node.
My solution is a GenServer
that calls a function every 30 secs and checks Node.list and if it is [] stop the node.
I have a questions
Is this the best solution or Erlang/OTP have a straight forward solution for that?
I searched and didn't find my answer on this document: http://erlang.org/doc/design_principles/distributed_applications.html
Upvotes: 0
Views: 147
Reputation: 724
There's :global_group.monitor/1 function that can be used to get notification when some node in cluster went up or down:
defmodule NodeMonitor do
def start_link do
{:ok, spawn_link fn ->
:global_group.monitor_nodes true
monitor()
end}
end
def monitor do
receive do
{:nodeup, node} -> Logger.info "NodeMonitor: #{node} joined"
{:nodedown, node} -> Logger.warn "NodeMonitor: #{node} left"
end
monitor()
end
end
Upvotes: 1