pub struct QotLoginHealth { /* private fields */ }Implementations§
Source§impl QotLoginHealth
impl QotLoginHealth
pub fn new() -> Self
Sourcepub fn with_ladder(ladder: [u64; 4]) -> Self
pub fn with_ladder(ladder: [u64; 4]) -> Self
v1.4.97 P1-D-B: test-friendly construction with explicit ladder.
pub fn backoff_ms_ladder(&self) -> [u64; 4]
Sourcepub fn record_qot_logined_false(&self)
pub fn record_qot_logined_false(&self)
Call from query handler / health-poll task whenever
LoginCache::is_logged_in() returns false while backend is connected.
Updates last-observed timestamp + monotonic counter.
Sourcepub fn record_relogin_attempt(&self)
pub fn record_relogin_attempt(&self)
Call right before invoking the relogin code path. Records timestamp +
bumps total_relogin_attempts.
Sourcepub fn record_relogin_success(&self)
pub fn record_relogin_success(&self)
Call after relogin completes successfully. Clears failure counter, records timestamp, bumps success monotonic.
Sourcepub fn record_relogin_failure(&self)
pub fn record_relogin_failure(&self)
Call after relogin attempt fails. Bumps consecutive failure counter
(drives exponential backoff in should_attempt_relogin).
Sourcepub fn should_attempt_relogin(
&self,
qot_logined_now: bool,
backend_connected: bool,
) -> bool
pub fn should_attempt_relogin( &self, qot_logined_now: bool, backend_connected: bool, ) -> bool
Decision API for the 30s polling task.
Returns true iff:
- caller observed a stale QOT login while the backend TCP is connected:
qot_logined_now=falseANDbackend_connected=true; AND - enough time has passed since
last_relogin_attempt_at_msper exponential-backoff schedule:- 0 failures → 60s
- 1 failure → 120s
- 2 failures → 240s
- 3+ failures → 600s cap
Caller is responsible for separately calling
record_relogin_attempt() then record_relogin_success() /
record_relogin_failure() after the relogin runs.
Sourcepub fn relogin_backoff_ms(&self) -> i64
pub fn relogin_backoff_ms(&self) -> i64
Current backoff window in ms based on consecutive_relogin_failures.
Public for tests / metrics; not intended for caller decision (use
should_attempt_relogin).
v1.4.97 P1-D-B: ladder is now env-tunable via
FUTU_QOT_RELOGIN_BACKOFF_MS=60000,120000,240000,600000. Default
values unchanged from v1.4.94 baseline.
Sourcepub fn try_begin_attempt(&self) -> bool
pub fn try_begin_attempt(&self) -> bool
v1.4.92: 尝试 acquire in-flight slot. 返 true 表示获取成功 (caller
现在可调 refresher), 返 false 表示已有别的 attempt 在跑 (caller skip).
用 compare_exchange(false, true, AcqRel, Relaxed) 而非 load + store
防止两个并发 tick 都看到 false → 都进 attempt.
Sourcepub fn end_attempt(&self)
pub fn end_attempt(&self)
v1.4.92: release in-flight slot (无论 attempt 成功或失败都该调).
Sourcepub fn open_circuit(&self)
pub fn open_circuit(&self)
v1.4.92: 触发 circuit_open (5 连续失败后调). 记 timestamp + 置 flag.
Sourcepub fn maybe_close_circuit(&self)
pub fn maybe_close_circuit(&self)
v1.4.92: 自动检查 + 重置 circuit (cooldown 过期则关闭 + 清 failure counter 给重试 fresh budget).
每次 polling tick 调一次, 不会引入额外开销 (atomic load + 比较).
Sourcepub fn should_attempt_relogin_v2(
&self,
qot_logined_now: bool,
backend_connected: bool,
) -> bool
pub fn should_attempt_relogin_v2( &self, qot_logined_now: bool, backend_connected: bool, ) -> bool
v1.4.92: 扩展 decision API — 包含 circuit_open 检查.
与 Self::should_attempt_relogin 关系:
- 先
maybe_close_circuit()检查 cooldown 是否过期 → 自动重置 - 若 circuit 仍 open → return false (跳所有 attempt)
- 否则 delegate 到
should_attempt_relogin(原 v1.4.90 backoff 逻辑)
调用方 (run_qot_login_health_loop) 应该用这个 v2 API 而不是 v1
的 should_attempt_relogin. v1 保留作 backward-compat (单测仍在用).
Sourcepub fn record_relogin_failure_with_circuit_check(&self)
pub fn record_relogin_failure_with_circuit_check(&self)
v1.4.92: 扩展版 record_relogin_failure — 失败后检查是否达 trip 阈值.
与 Self::record_relogin_failure 关系:
- 先调 record_relogin_failure (++ counter)
- 若 counter >= [
RELOGIN_CIRCUIT_TRIP_THRESHOLD] → 自动 open_circuit
caller 可选用 v1 (只 ++counter) 或 v2 (++ + 触发 trip). polling loop 实装应该用 v2.
Sourcepub fn snapshot(&self) -> QotLoginHealthSnapshot
pub fn snapshot(&self) -> QotLoginHealthSnapshot
Snapshot for /api/push-subscriber-info extension or future
/api/admin/qot-login-health endpoint.