Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added manager node monitor #827

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Lexical.RemoteControl.Application do
children =
if RemoteControl.project_node?() do
[
RemoteControl.ManagerNodeMonitor,
RemoteControl.Api.Proxy,
RemoteControl.Commands.Reindex,
RemoteControl.Module.Loader,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule Lexical.RemoteControl.ManagerNodeMonitor do
@moduledoc """
A node monitor that monitors the manager node for this project, and shuts down
the system if that node dies.
"""
use GenServer
require Logger

def start_link(_) do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end

@impl true
def init(_) do
case fetch_manager_node() do
{:ok, manager_node} ->
Node.monitor(manager_node, true)
{:ok, manager_node}

:error ->
Logger.warning("Could not determine manager node for monitoring.")
:ignore
end
end

@impl true
def handle_info({:nodedown, _}, state) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think state is the manager node here, maybe this is worth doing?

Suggested change
def handle_info({:nodedown, _}, state) do
def handle_info({:nodedown, manager}, manager) do

spawn(fn -> System.stop() end)
scohen marked this conversation as resolved.
Show resolved Hide resolved
{:noreply, state}
end

defp fetch_manager_node do
Enum.find_value(Node.list(), :error, fn node_name ->
string_name = Atom.to_string(node_name)

if String.starts_with?(string_name, "manager-") do
{:ok, node_name}
else
false
end
end)
end
end
Loading