Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85628466
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/pleroma/search/healthcheck.ex b/lib/pleroma/search/healthcheck.ex
index 9a2d9fdd6..170f29344 100644
--- a/lib/pleroma/search/healthcheck.ex
+++ b/lib/pleroma/search/healthcheck.ex
@@ -1,85 +1,85 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Search.Healthcheck do
@doc """
Monitors health of search backend to control processing of events based on health and availability.
"""
use GenServer
require Logger
@tick :timer.seconds(5)
@queue :search_indexing
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
@impl true
def init(_) do
state = %{healthy: false}
{:ok, state, {:continue, :start}}
end
@impl true
def handle_continue(:start, state) do
tick()
{:noreply, state}
end
@impl true
def handle_info(:check, state) do
urls = Pleroma.Search.healthcheck_endpoints()
new_state =
- if healthy?(urls) do
+ if check(urls) do
Oban.resume_queue(queue: @queue)
Map.put(state, :healthy, true)
else
Oban.pause_queue(queue: @queue)
Map.put(state, :healthy, false)
end
maybe_log_state_change(state, new_state)
tick()
{:noreply, new_state}
end
@impl true
- def handle_call(:check, _from, state) do
- status = Map.get(state, :healthy)
-
- {:reply, status, state, :hibernate}
+ def handle_call(:state, _from, state) do
+ {:reply, state, state, :hibernate}
end
- defp healthy?([]), do: true
+ def state, do: GenServer.call(__MODULE__, :state)
+
+ def check([]), do: true
- defp healthy?(urls) when is_list(urls) do
+ def check(urls) when is_list(urls) do
Enum.all?(
urls,
fn url ->
case Pleroma.HTTP.get(url) do
{:ok, %{status: 200}} -> true
_ -> false
end
end
)
end
- defp healthy?(_), do: true
+ def check(_), do: true
defp tick do
Process.send_after(self(), :check, @tick)
end
defp maybe_log_state_change(%{healthy: true}, %{healthy: false}) do
Logger.error("Pausing Oban queue #{@queue} due to search backend healthcheck failure")
end
defp maybe_log_state_change(%{healthy: false}, %{healthy: true}) do
Logger.info("Resuming Oban queue #{@queue} due to search backend healthcheck pass")
end
defp maybe_log_state_change(_, _), do: :ok
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Aug 8, 12:36 PM (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1723330
Default Alt Text
(2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment