Spaces:
Sleeping
Sleeping
jindalarishya commited on
Commit ·
abc73b3
1
Parent(s): 1de77cd
fix: increase Telegram httpx timeouts and retries for HuggingFace network latency
Browse files- src/telegram_bot.py +4 -4
src/telegram_bot.py
CHANGED
|
@@ -989,18 +989,18 @@ def init_telegram_webhook(token):
|
|
| 989 |
import time
|
| 990 |
while _webhook_loop is None: time.sleep(0.1)
|
| 991 |
telegram_bot = Bot(token=token)
|
| 992 |
-
telegram_application = ApplicationBuilder().token(token).request(HTTPXRequest(http_version="1.1")).build()
|
| 993 |
async def init():
|
| 994 |
last_exc = None
|
| 995 |
-
for attempt in range(1,
|
| 996 |
try:
|
| 997 |
await telegram_application.initialize()
|
| 998 |
await setup_bot_commands(telegram_application)
|
| 999 |
break
|
| 1000 |
except Exception as e:
|
| 1001 |
last_exc = e
|
| 1002 |
-
print(f"Telegram network not ready, retrying in
|
| 1003 |
-
await asyncio.sleep(
|
| 1004 |
else:
|
| 1005 |
raise last_exc
|
| 1006 |
setup_telegram_handlers(telegram_application)
|
|
|
|
| 989 |
import time
|
| 990 |
while _webhook_loop is None: time.sleep(0.1)
|
| 991 |
telegram_bot = Bot(token=token)
|
| 992 |
+
telegram_application = ApplicationBuilder().token(token).request(HTTPXRequest(http_version="1.1", connect_timeout=60, read_timeout=60, write_timeout=60, pool_timeout=60)).build()
|
| 993 |
async def init():
|
| 994 |
last_exc = None
|
| 995 |
+
for attempt in range(1, 11):
|
| 996 |
try:
|
| 997 |
await telegram_application.initialize()
|
| 998 |
await setup_bot_commands(telegram_application)
|
| 999 |
break
|
| 1000 |
except Exception as e:
|
| 1001 |
last_exc = e
|
| 1002 |
+
print(f"Telegram network not ready, retrying in 15s... (attempt {attempt}/10: {e})", flush=True)
|
| 1003 |
+
await asyncio.sleep(15)
|
| 1004 |
else:
|
| 1005 |
raise last_exc
|
| 1006 |
setup_telegram_handlers(telegram_application)
|