fix: tune telegram polling for proxy stability

This commit is contained in:
ngfchl
2026-07-07 10:36:26 +08:00
parent 57656a3cc3
commit b04fdfb130
+8 -3
View File
@@ -47,7 +47,7 @@ def polling_error_callback(exc):
if now - _last_polling_error_log < 60:
return
_last_polling_error_log = now
logger.warning(f"⚠️ TG polling 网络波动,已自动重试: {type(exc).__name__}: {exc}")
logger.warning(f"⚠️ TG polling 长轮询连接被代理中断,已自动重试: {type(exc).__name__}: {exc}")
async def global_error_handler(update: object, context: ContextTypes.DEFAULT_TYPE):
@@ -78,7 +78,7 @@ async def start_tg_bot():
proxy=PROXY_URL,
connection_pool_size=8,
connect_timeout=30.0,
read_timeout=60.0,
read_timeout=15.0,
write_timeout=30.0,
pool_timeout=30.0,
)
@@ -95,7 +95,12 @@ async def start_tg_bot():
await tg_app.initialize()
await tg_app.start()
await tg_app.updater.start_polling(drop_pending_updates=False, error_callback=polling_error_callback)
await tg_app.updater.start_polling(
poll_interval=0.5,
timeout=3,
drop_pending_updates=False,
error_callback=polling_error_callback,
)
# 菜单
commands = [