Skip to main content

readyz

Function readyz 

Source
pub async fn readyz() -> (StatusCode, Json<Value>)
Expand description

GET /readyz — readiness 就绪探针。

流程:

  1. 取连接池状态(纯内存快照,无 I/O);
  2. 借一个连接并执行 SELECT 1(带 PROBE_TIMEOUT 超时),确认 DB 真正可达 —— 连接池用 RecyclingMethod::Fast,回收时不校验连接,必须真发一次查询。

直接用 DB_POOL.get() 而非 get_conn():后者有指数退避重试(约 1.6s), 探针应当快速失败而非等待重试。

返回:

  • 200 {status:"ready", db:"ok", pool:{...}} — 一切正常
  • 503 {status:"unready", db:"down"|"error"|"timeout", ...} — DB 不可达