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
35
bot.py
35
bot.py
|
|
@ -488,18 +488,29 @@ async def send_video_to_admin_bot(video_path: str, url: str, from_user=None):
|
||||||
if user_info:
|
if user_info:
|
||||||
caption += f"\n👤 {user_info}"
|
caption += f"\n👤 {user_info}"
|
||||||
|
|
||||||
# Отправляем видео
|
# Отправляем видео (с ретраем — транспортные ошибки httpx при аплоаде бывают и здесь)
|
||||||
with open(video_path, 'rb') as video_file:
|
send_retries = 3
|
||||||
await admin_bot.send_video(
|
for attempt in range(send_retries):
|
||||||
chat_id=admin_chat_id,
|
video_file = open(video_path, 'rb')
|
||||||
video=video_file,
|
try:
|
||||||
caption=caption,
|
await admin_bot.send_video(
|
||||||
supports_streaming=True,
|
chat_id=admin_chat_id,
|
||||||
read_timeout=600,
|
video=video_file,
|
||||||
write_timeout=600,
|
caption=caption,
|
||||||
connect_timeout=60,
|
supports_streaming=True,
|
||||||
pool_timeout=60
|
read_timeout=600,
|
||||||
)
|
write_timeout=600,
|
||||||
|
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}")
|
logger.info(f"Видео отправлено админ боту: {video_path}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue