Spaces:
Sleeping
Sleeping
| """ | |
| backend/workers/scheduler.py | |
| Simple scheduler wiring for Celery beat. | |
| This file merely defines a schedule mapping that celeryconfig.py/ Celery app can import. | |
| You can use Celery Beat (celery -A backend.workers.celeryconfig beat) or | |
| run APScheduler to call the task functions if not using Celery beat. | |
| """ | |
| from datetime import timedelta | |
| import os | |
| # Recommended schedule configuration for production: | |
| SCHEDULE = { | |
| # run daily metrics every day at midnight UTC | |
| "daily-metrics": { | |
| "task": "backend.workers.analytics_worker.compute_daily_metrics", | |
| "schedule": {"type": "crontab", "hour": 0, "minute": 5}, # small delay after midnight | |
| }, | |
| # run RAG quality checks nightly | |
| "rag-quality-nightly": { | |
| "task": "backend.workers.analytics_worker.compute_rag_quality", | |
| "schedule": {"type": "crontab", "hour": 2, "minute": 30}, | |
| "args": (20, 3) | |
| } | |
| } | |
| # If you prefer periodic seconds schedule (for local dev), | |
| # you can expose an alternate schedule via env: | |
| if os.getenv("LOCAL_CELERY_QUICK", "0") == "1": | |
| SCHEDULE = { | |
| "daily-metrics": {"task": "backend.workers.analytics_worker.compute_daily_metrics", | |
| "schedule": timedelta(seconds=60)}, # every minute for dev | |
| "rag-quality": {"task": "backend.workers.analytics_worker.compute_rag_quality", | |
| "schedule": timedelta(seconds=120)} | |
| } | |