Make it easier to read the state for debugging purposes and expose functions for testing
This commit is contained in:
parent
3474b42ce3
commit
f2b0d5f1d0
|
@ -32,7 +32,7 @@ def handle_info(:check, state) do
|
||||||
urls = Pleroma.Search.healthcheck_endpoints()
|
urls = Pleroma.Search.healthcheck_endpoints()
|
||||||
|
|
||||||
new_state =
|
new_state =
|
||||||
if healthy?(urls) do
|
if check(urls) do
|
||||||
Oban.resume_queue(queue: @queue)
|
Oban.resume_queue(queue: @queue)
|
||||||
Map.put(state, :healthy, true)
|
Map.put(state, :healthy, true)
|
||||||
else
|
else
|
||||||
|
@ -47,15 +47,15 @@ def handle_info(:check, state) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def handle_call(:check, _from, state) do
|
def handle_call(:state, _from, state) do
|
||||||
status = Map.get(state, :healthy)
|
{:reply, state, state, :hibernate}
|
||||||
|
|
||||||
{:reply, status, state, :hibernate}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp healthy?([]), do: true
|
def state, do: GenServer.call(__MODULE__, :state)
|
||||||
|
|
||||||
defp healthy?(urls) when is_list(urls) do
|
def check([]), do: true
|
||||||
|
|
||||||
|
def check(urls) when is_list(urls) do
|
||||||
Enum.all?(
|
Enum.all?(
|
||||||
urls,
|
urls,
|
||||||
fn url ->
|
fn url ->
|
||||||
|
@ -67,7 +67,7 @@ defp healthy?(urls) when is_list(urls) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp healthy?(_), do: true
|
def check(_), do: true
|
||||||
|
|
||||||
defp tick do
|
defp tick do
|
||||||
Process.send_after(self(), :check, @tick)
|
Process.send_after(self(), :check, @tick)
|
||||||
|
|
Loading…
Reference in New Issue