diff --git a/lib/oban/sonar.ex b/lib/oban/sonar.ex index 434dcb2c..f477b7ad 100644 --- a/lib/oban/sonar.ex +++ b/lib/oban/sonar.ex @@ -9,9 +9,9 @@ defmodule Oban.Sonar do defstruct [ :conf, :timer, - interval: :timer.seconds(15), + interval: :timer.seconds(5), nodes: %{}, - stale_mult: 2, + stale_mult: 6, status: :unknown ] @@ -45,12 +45,16 @@ defmodule Oban.Sonar do @impl GenServer def handle_continue(:start, state) do :ok = Notifier.listen(state.conf.name, :sonar) - :ok = Notifier.notify(state.conf, :sonar, %{node: state.conf.node, ping: :ping}) + :ok = Notifier.notify(state.conf, :sonar, %{node: state.conf.node, ping: true}) {:noreply, schedule_ping(state)} end @impl GenServer + def handle_call(:get_nodes, _from, state) do + {:reply, Map.keys(state.nodes), state} + end + def handle_call(:get_status, _from, state) do {:reply, state.status, state} end @@ -58,7 +62,7 @@ defmodule Oban.Sonar do def handle_call(:prune_nodes, _from, state) do state = prune_stale_nodes(state) - {:reply, state.nodes, state} + {:reply, Map.keys(state.nodes), state} end @impl GenServer diff --git a/test/oban/sonar_test.exs b/test/oban/sonar_test.exs index 3d1ca7d8..f7c4770c 100644 --- a/test/oban/sonar_test.exs +++ b/test/oban/sonar_test.exs @@ -64,8 +64,8 @@ defmodule Oban.SonarTest do |> Registry.whereis(Sonar) |> GenServer.call(:prune_nodes) - assert Map.has_key?(nodes, "web.1") - refute Map.has_key?(nodes, "web.2") + assert "web.1" in nodes + refute "web.2" in nodes end end end