lizerk d5b4ae9f43 refactor: Полный переход на новую архитектуру уведомлений v2.0
BREAKING CHANGES:
- Удалена старая система (6 моделей → 2 модели)
- models_new.py → models.py (Notification, UserChannelPreferences)
- signals_new.py → signals.py (notify.send API)
- admin_new.py → admin.py

Новая архитектура:
- Все отправки через Celery (полностью асинхронно)
- Модульная структура tasks/ (base, email, push, websocket)
- Каждый канал - отдельный класс задачи наследующий BaseNotificationTask
- Rate limiting, retry, приоритеты из коробки

Обратная совместимость:
- Создан services.py facade для старого API
- NotificationService.create_notification() работает через notify.send()
- Старый код продолжает работать без изменений

Удалено:
- Старые models.py, signals.py, admin.py, tasks.py (→ .old)
- telegram_bot.py, telegram_models.py (Telegram отключен)
- test_views.py, views.py, urls.py (устаревшие)

Создано:
- tasks/ модуль с классовой архитектурой (как senders/)
- tasks/base.py - BaseNotificationTask
- tasks/email.py - EmailNotificationTask + DigestEmailTask
- tasks/push.py - PushNotificationTask
- tasks/websocket.py - WebSocketNotificationTask

Обновлено:
- apps.py - загружает signals, channels, tasks
- channels.py - все отправки через Celery задачи
- Все импорты models_new → models
2026-03-09 16:36:14 +03:00

41 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Celery задачи для отправки Web Push уведомлений
"""
from .base import BaseNotificationTask
class PushNotificationTask(BaseNotificationTask):
"""
Celery задача для асинхронной отправки Web Push уведомлений.
Особенности:
- Rate limiting: 50 push/минуту
- Retry: 2 попытки с интервалом 1 минута
- Автоматическое удаление неактивных устройств
"""
task_name = "notifications.send_push"
max_retries = 2
retry_delay = 60 # 1 минута между попытками
rate_limit = '50/m' # Не более 50 push в минуту
def send_notification(self, notification, **kwargs) -> bool:
"""
Отправляет Web Push через PushNotificationSender.
Args:
notification: Объект Notification
**kwargs: Дополнительные параметры
Returns:
True если успешно (хотя бы одно устройство), False иначе
"""
from notifications.senders.push import PushNotificationSender
sender = PushNotificationSender()
return sender.send(notification, **kwargs)
# Регистрируем задачу в Celery
send_push_notification = PushNotificationTask.register_task()