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:
1 parent
0807b130e9
commit
fd7bfcd9d3
1 file changed
+7
-2
+7
-2
@@ -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__":
|
||||
|
||||
Reference in new issue
Block a user