fix(bot): retry admin video upload on transient httpx transport errors
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 1m44s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 1m44s
send_video_to_admin_bot() had no retry, unlike the client-facing reply_video() path fixed earlier — a transient httpx.ReadError during upload silently dropped the admin copy while the user still got their video, since this function swallows its own exceptions.
This commit is contained in:
parent
67dba21ff9
commit
ac2bd8f644
1 changed files with 24 additions and 13 deletions
15
bot.py
15
bot.py
|
|
@ -488,8 +488,11 @@ async def send_video_to_admin_bot(video_path: str, url: str, from_user=None):
|
|||
if user_info:
|
||||
caption += f"\n👤 {user_info}"
|
||||
|
||||
# Отправляем видео
|
||||
with open(video_path, 'rb') as video_file:
|
||||
# Отправляем видео (с ретраем — транспортные ошибки httpx при аплоаде бывают и здесь)
|
||||
send_retries = 3
|
||||
for attempt in range(send_retries):
|
||||
video_file = open(video_path, 'rb')
|
||||
try:
|
||||
await admin_bot.send_video(
|
||||
chat_id=admin_chat_id,
|
||||
video=video_file,
|
||||
|
|
@ -500,6 +503,14 @@ async def send_video_to_admin_bot(video_path: str, url: str, from_user=None):
|
|||
connect_timeout=60,
|
||||
pool_timeout=60
|
||||
)
|
||||
break
|
||||
except Exception as send_error:
|
||||
if attempt == send_retries - 1:
|
||||
raise
|
||||
logger.warning(f"Отправка видео админ боту: попытка {attempt + 1}/{send_retries} не удалась: {send_error}")
|
||||
await asyncio.sleep((attempt + 1) * 2)
|
||||
finally:
|
||||
video_file.close()
|
||||
|
||||
logger.info(f"Видео отправлено админ боту: {video_path}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue