mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-02-23 04:40:59 +00:00
@@ -1,5 +1,6 @@
|
||||
"""FastAPI dependencies for cabinet module."""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from aiogram import Bot
|
||||
@@ -129,7 +130,10 @@ async def get_current_cabinet_user(
|
||||
if not is_admin:
|
||||
try:
|
||||
bot = _get_channel_check_bot()
|
||||
chat_member = await bot.get_chat_member(chat_id=settings.CHANNEL_SUB_ID, user_id=user.telegram_id)
|
||||
chat_member = await asyncio.wait_for(
|
||||
bot.get_chat_member(chat_id=settings.CHANNEL_SUB_ID, user_id=user.telegram_id),
|
||||
timeout=10.0,
|
||||
)
|
||||
# Не закрываем сессию - бот переиспользуется
|
||||
|
||||
if chat_member.status not in ['member', 'administrator', 'creator']:
|
||||
@@ -143,6 +147,9 @@ async def get_current_cabinet_user(
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning(f'Timeout checking channel subscription for user {user.telegram_id}')
|
||||
# Don't block user if check times out
|
||||
except Exception as e:
|
||||
logger.warning(f'Failed to check channel subscription for user {user.telegram_id}: {e}')
|
||||
# Don't block user if check fails
|
||||
|
||||
@@ -41,7 +41,7 @@ else:
|
||||
pool_kwargs = {
|
||||
'pool_size': 30, # Увеличен с 20
|
||||
'max_overflow': 50, # Увеличен с 30
|
||||
'pool_timeout': 30,
|
||||
'pool_timeout': 60, # Увеличен с 30 для обработки пиковых нагрузок
|
||||
'pool_recycle': 1800, # Уменьшен с 3600 до 30 мин для более быстрого recycling
|
||||
'pool_pre_ping': True,
|
||||
# Агрессивная очистка мертвых соединений
|
||||
@@ -61,7 +61,7 @@ _pg_connect_args = {
|
||||
'idle_in_transaction_session_timeout': '300000', # 5 минут
|
||||
},
|
||||
'command_timeout': 60,
|
||||
'timeout': 30, # Увеличен с 10 до 30 сек для высокой нагрузки
|
||||
'timeout': 60, # Увеличен с 30 до 60 сек для обработки пиковых нагрузок
|
||||
}
|
||||
|
||||
engine = create_async_engine(
|
||||
@@ -94,7 +94,7 @@ AsyncSessionLocal = async_sessionmaker(
|
||||
# RETRY LOGIC FOR DATABASE OPERATIONS
|
||||
# ============================================================================
|
||||
|
||||
RETRYABLE_EXCEPTIONS = (OperationalError, InterfaceError, ConnectionRefusedError, OSError)
|
||||
RETRYABLE_EXCEPTIONS = (OperationalError, InterfaceError, ConnectionRefusedError, OSError, TimeoutError)
|
||||
DEFAULT_RETRY_ATTEMPTS = 3
|
||||
DEFAULT_RETRY_DELAY = 0.5 # секунды
|
||||
|
||||
|
||||
2
app/external/remnawave_api.py
vendored
2
app/external/remnawave_api.py
vendored
@@ -341,7 +341,7 @@ class RemnaWaveAPI:
|
||||
|
||||
connector = aiohttp.TCPConnector(**connector_kwargs)
|
||||
|
||||
session_kwargs = {'timeout': aiohttp.ClientTimeout(total=30), 'headers': headers, 'connector': connector}
|
||||
session_kwargs = {'timeout': aiohttp.ClientTimeout(total=60, connect=10), 'headers': headers, 'connector': connector}
|
||||
|
||||
if cookies:
|
||||
session_kwargs['cookies'] = cookies
|
||||
|
||||
@@ -191,14 +191,24 @@ class NotificationDeliveryService:
|
||||
try:
|
||||
from aiogram.exceptions import TelegramBadRequest, TelegramForbiddenError
|
||||
|
||||
await bot.send_message(
|
||||
chat_id=user.telegram_id,
|
||||
text=message,
|
||||
reply_markup=markup,
|
||||
parse_mode='HTML',
|
||||
await asyncio.wait_for(
|
||||
bot.send_message(
|
||||
chat_id=user.telegram_id,
|
||||
text=message,
|
||||
reply_markup=markup,
|
||||
parse_mode='HTML',
|
||||
),
|
||||
timeout=15.0,
|
||||
)
|
||||
return True
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning(
|
||||
'Timeout при отправке Telegram уведомления пользователю %s',
|
||||
user.telegram_id,
|
||||
)
|
||||
return False
|
||||
|
||||
except TelegramForbiddenError:
|
||||
logger.warning(
|
||||
'Telegram user %s заблокировал бота',
|
||||
|
||||
Reference in New Issue
Block a user