Handle_info is not getting called

I am trying to run a distributed program where I need to inform other nodes regarding the status of all nodes, i.e. either the node is up or down. I am not able to receive messages from handle_info.

def main(target_count) do
    Worm.Application.start(:normal, target_count)
end

Here it initializes the application with an argument, which I will later use.

def start(type, args) do
    children = [
      {Worm.Observer, args},
    ]
    opts = [strategy: :one_for_one, name: Worm.Supervisor]
    Supervisor.start_link(children, opts)
  end

The application initializes Worm.Observer which keeps a check on which nodes and Up and DOWN.

def start_link(total_count) do
    GenServer.start_link(__MODULE__, %{target_count: total_count})
  end

  @impl GenServer
  def init(state) do
    :net_kernel.monitor_nodes(true)
    {:ok, state}
  end

  @impl GenServer
  def handle_info({:nodedown, node}, state) do
    Logger.info("--- Node down: #{node}")
    {:noreply, state}
  end

  @impl GenServer
  def handle_info({:nodeup, node}, state) do
    Logger.info("--- Node up: #{node}")
    {:noreply, state}
  end

What am I doing wrong here that the nodes are not able to see the Logger.info messages.

1 Like

Is the :net_kernel.monitor_nodes(true) call successful?

yes it returns :ok