1f0fef114b
- Add ContextVarsMiddleware for automatic user_id/chat_id/username binding via structlog contextvars (aiogram) and http_method/http_path (FastAPI) - Use bound_contextvars() context manager instead of clear_contextvars() to safely restore previous state instead of wiping all context - Register ContextVarsMiddleware as outermost middleware (before GlobalError) so all error logs include user context - Replace structlog.get_logger() with structlog.get_logger(__name__) across 270 calls in 265 files for meaningful logger names - Switch wrapper_class from BoundLogger to make_filtering_bound_logger() for pre-processor level filtering (performance optimization) - Migrate 1411 %-style positional arg logger calls to structlog kwargs style across 161 files via AST script - Migrate log_rotation_service.py from stdlib logging to structlog - Add payment module prefixes to TelegramNotifierProcessor.IGNORED_LOGGER_PREFIXES and ExcludePaymentFilter.PAYMENT_MODULES to prevent payment data leaking to Telegram notifications and general log files - Fix LoggingMiddleware: add from_user null-safety for channel posts, switch time.time() to time.monotonic() for duration measurement - Remove duplicate logger assignments in purchase.py, config.py, inline.py, and admin/payments.py
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from datetime import datetime
|
|
|
|
from aiogram import types
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database.models import Subscription, User
|
|
from app.services.admin_notification_service import AdminNotificationService
|
|
|
|
from .common import logger
|
|
|
|
|
|
async def send_trial_notification(
|
|
callback: types.CallbackQuery, db: AsyncSession, db_user: User, subscription: Subscription
|
|
):
|
|
try:
|
|
notification_service = AdminNotificationService(callback.bot)
|
|
await notification_service.send_trial_activation_notification(db, db_user, subscription)
|
|
except Exception as e:
|
|
logger.error('Ошибка отправки уведомления о триале', error=e)
|
|
|
|
|
|
async def send_purchase_notification(
|
|
callback: types.CallbackQuery,
|
|
db: AsyncSession,
|
|
db_user: User,
|
|
subscription: Subscription,
|
|
transaction_id: int,
|
|
period_days: int,
|
|
was_trial_conversion: bool = False,
|
|
):
|
|
try:
|
|
from app.database.crud.transaction import get_transaction_by_id
|
|
|
|
transaction = await get_transaction_by_id(db, transaction_id)
|
|
if transaction:
|
|
notification_service = AdminNotificationService(callback.bot)
|
|
await notification_service.send_subscription_purchase_notification(
|
|
db, db_user, subscription, transaction, period_days, was_trial_conversion
|
|
)
|
|
except Exception as e:
|
|
logger.error('Ошибка отправки уведомления о покупке', error=e)
|
|
|
|
|
|
async def send_extension_notification(
|
|
callback: types.CallbackQuery,
|
|
db: AsyncSession,
|
|
db_user: User,
|
|
subscription: Subscription,
|
|
transaction_id: int,
|
|
extended_days: int,
|
|
old_end_date: datetime,
|
|
):
|
|
try:
|
|
from app.database.crud.transaction import get_transaction_by_id
|
|
|
|
transaction = await get_transaction_by_id(db, transaction_id)
|
|
if transaction:
|
|
notification_service = AdminNotificationService(callback.bot)
|
|
await notification_service.send_subscription_extension_notification(
|
|
db, db_user, subscription, transaction, extended_days, old_end_date
|
|
)
|
|
except Exception as e:
|
|
logger.error('Ошибка отправки уведомления о продлении', error=e)
|