File size: 1,410 Bytes
aa63765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
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)}
    }