prop/lib/microwaveprop_web/controllers/health_controller.ex
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

40 lines
1.4 KiB
Elixir

defmodule MicrowavepropWeb.HealthController do
@moduledoc """
Two separate probe endpoints for Kubernetes:
* `live/2` — liveness only. Returns 200 as long as the BEAM can
serve an HTTP request. Must NOT touch the database: a slow or
saturated Ecto pool would otherwise cascade into SIGKILL across
every replica simultaneously. Used as the `livenessProbe`
target.
* `check/2` — readiness. Also pings the Repo via `SELECT 1` so
the pod is taken out of the Service endpoint set when the DB
is unreachable. Used as the `readinessProbe` target.
Splitting these two concerns is specifically a fix for an incident
where PromEx's Oban queue-depth poller held a connection for > 15s,
queued up every other checkout, and the liveness probe's `SELECT 1`
timed out before it could ever acquire the pool — so the kubelet
killed every pod every few minutes even though the BEAM was healthy.
"""
use MicrowavepropWeb, :controller
alias Ecto.Adapters.SQL
@spec live(Plug.Conn.t(), map()) :: Plug.Conn.t()
def live(conn, _params) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "ok")
end
@spec check(Plug.Conn.t(), map()) :: Plug.Conn.t()
def check(conn, _params) do
_ = SQL.query!(Microwaveprop.Repo, "SELECT 1")
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "ok")
end
end