Include compact worker in readiness

This commit is contained in:
SimpleTest 2026-08-09 06:40:49 +03:00
parent 94d4e6dae1
commit a65d7d126f
2 changed files with 26 additions and 3 deletions

View File

@ -7,10 +7,24 @@ defmodule WhoNeedHelpWeb.HealthController do
if WhoNeedHelpWeb.DrainState.draining?() do
conn |> put_status(:service_unavailable) |> json(%{status: "draining"})
else
case Ecto.Adapters.SQL.query(WhoNeedHelp.Repo, "SELECT 1", []) do
{:ok, _} -> json(conn, %{status: "ready"})
{:error, _} -> conn |> put_status(:service_unavailable) |> json(%{status: "not_ready"})
database_ready? =
match?({:ok, _}, Ecto.Adapters.SQL.query(WhoNeedHelp.Repo, "SELECT 1", []))
if ready?(
Application.fetch_env!(:who_need_help, :app_role),
database_ready?,
Oban.whereis(Oban)
) do
json(conn, %{status: "ready"})
else
conn |> put_status(:service_unavailable) |> json(%{status: "not_ready"})
end
end
end
@doc false
def ready?(:combined, database_ready?, oban_pid),
do: database_ready? and is_pid(oban_pid)
def ready?(_role, database_ready?, _oban_pid), do: database_ready?
end

View File

@ -165,6 +165,15 @@ defmodule WhoNeedHelpWeb.PageControllerTest do
|> json_response(200)
end
test "combined readiness also requires its in-process Oban worker" do
assert WhoNeedHelpWeb.HealthController.ready?(:combined, true, self())
refute WhoNeedHelpWeb.HealthController.ready?(:combined, true, nil)
refute WhoNeedHelpWeb.HealthController.ready?(:combined, false, self())
assert WhoNeedHelpWeb.HealthController.ready?(:web, true, nil)
refute WhoNeedHelpWeb.HealthController.ready?(:web, false, self())
end
test "GET /safety selects Ukrainian locale and keeps it in the session", %{conn: conn} do
conn = get(conn, ~p"/safety?locale=uk")
assert html_response(conn, 200) =~ "Правила безпеки"