- Создана система отслеживания миграций (MigrationRepository, таблица migrations) - Добавлен скрипт apply_migrations.py для автоматического применения миграций - Созданы CI/CD пайплайны (.github/workflows/ci.yml, deploy.yml) - Обновлена документация по миграциям в database-patterns.md - Миграции применяются автоматически при деплое в продакшн
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
"""Decorators and utility functions for private handlers"""
|
|
|
|
# Standard library imports
|
|
import traceback
|
|
from typing import Any, Callable
|
|
|
|
# Third-party imports
|
|
from aiogram import types
|
|
# Local imports
|
|
from logs.custom_logger import logger
|
|
|
|
|
|
def error_handler(func: Callable[..., Any]) -> Callable[..., Any]:
|
|
"""Decorator for centralized error handling"""
|
|
async def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
try:
|
|
return await func(*args, **kwargs)
|
|
except Exception as e:
|
|
logger.error(f"Error in {func.__name__}: {str(e)}")
|
|
# Try to send error to logs if possible
|
|
try:
|
|
message = next((arg for arg in args if isinstance(arg, types.Message)), None)
|
|
if message and hasattr(message, 'bot'):
|
|
from helper_bot.utils.base_dependency_factory import \
|
|
get_global_instance
|
|
bdf = get_global_instance()
|
|
important_logs = bdf.settings['Telegram']['important_logs']
|
|
await message.bot.send_message(
|
|
chat_id=important_logs,
|
|
text=f"Произошла ошибка в {func.__name__}: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
|
)
|
|
except Exception:
|
|
# If we can't log the error, at least it was logged to logger
|
|
pass
|
|
raise
|
|
return wrapper
|