fix(heartbeat): blocking_timeout 5→0,多 replica 不排隊等鎖避免重複發送
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 14m0s

3 個 replica 各自跑 loop,blocking_timeout=5.0 導致鎖釋放後
其他 replica 依序拿鎖,每次心跳最多發 3 條。
改為 blocking_timeout=0:拿不到鎖立刻跳過,同週期只發一條。

2026-04-12 ogt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-04-12 16:13:41 +08:00
parent a28625f088
commit effd78807e

View File

@@ -4674,8 +4674,9 @@ class TelegramGateway:
# 分散式鎖:同一心跳週期只有一個 replica 發報告
# timeout=25*60 確保下一次心跳前鎖一定釋放(心跳間隔 30min
# blocking_timeout=0: 鎖被佔用時立刻跳過,不排隊等待(避免多 replica 輪流發)
try:
async with RedisLock("heartbeat:leader", timeout=25 * 60, blocking_timeout=5.0):
async with RedisLock("heartbeat:leader", timeout=25 * 60, blocking_timeout=0):
report = await HeartbeatReportService().collect()
text = report_to_telegram_html(report)