Backend: - Notification model + Alembic migration - Notification service: CRUD, mark read, unread count, pending scheduled - WebSocket manager singleton for real-time push - WebSocket endpoint /ws/notifications with JWT auth via query param - APScheduler integration: periodic notification sender (every 60s), daily proactive health review job (8 AM) - AI tool: schedule_notification (immediate or scheduled) - Health review worker: analyzes user memory via Claude, creates ai_generated notifications with WebSocket push Frontend: - Notification API client + Zustand store - WebSocket hook with auto-reconnect (exponential backoff) - Notification bell in header with unread count badge + dropdown - Notifications page with type badges, mark read, mark all read - WebSocket initialized in AppLayout for app-wide real-time updates - Enabled notifications nav in sidebar - English + Russian translations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
from apscheduler.triggers.cron import CronTrigger
|
|
from apscheduler.triggers.date import DateTrigger
|
|
|
|
scheduler = AsyncIOScheduler()
|
|
|
|
|
|
def start_scheduler():
|
|
if not scheduler.running:
|
|
# Register periodic jobs
|
|
from app.workers.notification_sender import send_pending_notifications
|
|
scheduler.add_job(
|
|
send_pending_notifications,
|
|
trigger=CronTrigger(second="0", minute="*"), # every minute
|
|
id="send_pending_notifications",
|
|
replace_existing=True,
|
|
)
|
|
|
|
from app.workers.health_review import run_daily_health_review
|
|
scheduler.add_job(
|
|
run_daily_health_review,
|
|
trigger=CronTrigger(hour=8, minute=0),
|
|
id="daily_health_review",
|
|
replace_existing=True,
|
|
)
|
|
|
|
scheduler.start()
|
|
|
|
|
|
def shutdown_scheduler():
|
|
if scheduler.running:
|
|
scheduler.shutdown(wait=False)
|
|
|
|
|
|
def schedule_one_time(job_id: str, run_date, func, **kwargs):
|
|
scheduler.add_job(func, trigger=DateTrigger(run_date=run_date), id=job_id, replace_existing=True, kwargs=kwargs)
|
|
|
|
|
|
def schedule_recurring(job_id: str, cron_expr: str, func, **kwargs):
|
|
trigger = CronTrigger.from_crontab(cron_expr)
|
|
scheduler.add_job(func, trigger=trigger, id=job_id, replace_existing=True, kwargs=kwargs)
|