From e03ed09222c7147ec729b292dcf6d671a65991d2 Mon Sep 17 00:00:00 2001 From: feng19 Date: Thu, 7 Mar 2024 09:53:02 +0800 Subject: [PATCH] feat: only ping when monitoring --- lib/x_trace/node_listener.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/x_trace/node_listener.ex b/lib/x_trace/node_listener.ex index 52daeeb..608998a 100644 --- a/lib/x_trace/node_listener.ex +++ b/lib/x_trace/node_listener.ex @@ -23,7 +23,7 @@ defmodule XTrace.NodeListener do def init(_) do init_erlang_distributed() :timer.send_interval(1000, self(), :tick) - {:ok, nil} + {:ok, false} end @impl true @@ -38,7 +38,7 @@ defmodule XTrace.NodeListener do end def handle_info(:tick, state) do - :net_adm.world() + if state, do: :net_adm.world() {:noreply, state} end @@ -48,11 +48,11 @@ defmodule XTrace.NodeListener do end @impl true - def handle_call({:monitor, bool}, _from, state) do + def handle_call({:monitor, bool}, _from, _state) do # ping world nodes :net_adm.world() :net_kernel.monitor_nodes(bool, node_type: :all) - {:reply, :ok, state} + {:reply, :ok, bool} end defp init_erlang_distributed do