fix(qqapp): exponential reconnect backoff

Replace fixed 5s sleep with the same backoff pattern already used in
dcapp.py: 5 -> 10 -> 20 -> ... -> 300s, resetting to 5s when a session
survived >=60s. Uses time.monotonic() to avoid clock-jump skew.
This commit is contained in:
Tianye Song committed 2026-05-07 10:29:37 +08:00
1 parent 0807b130e9
commit fd7bfcd9d3
1 file changed
+7 -2
+7 -2
View File
@@ -103,14 +103,19 @@ class QQApp(AgentChatMixin):
async def start(self):
self.client = _make_bot_class(self)()
delay, max_delay = 5, 300
while True:
started_at = time.monotonic()
try:
print(f"[QQ] bot starting... {time.strftime('%m-%d %H:%M')}")
await self.client.start(appid=APP_ID, secret=APP_SECRET)
except Exception as e:
print(f"[QQ] bot error: {e}")
print("[QQ] reconnect in 5s...")
await asyncio.sleep(5)
if time.monotonic() - started_at >= 60:
delay = 5
print(f"[QQ] reconnect in {delay}s...")
await asyncio.sleep(delay)
delay = min(delay * 2, max_delay)
if __name__ == "__main__":