pahvalentines/backend/tasks/celery_app.py
2026-01-31 07:30:26 -06:00

53 lines
1.6 KiB
Python

"""Celery application configuration and Beat schedule."""
import os
import sys
from celery import Celery
from celery.schedules import crontab
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app.config import settings
# Create Celery app
app = Celery("pah_workers")
# Configure Celery
app.config_from_object(
{
"broker_url": settings.CELERY_BROKER_URL,
"result_backend": settings.CELERY_RESULT_BACKEND,
"task_serializer": "json",
"result_serializer": "json",
"accept_content": ["json"],
"timezone": "UTC",
"task_track_started": True,
"task_acks_late": True,
"worker_prefetch_multiplier": 1,
}
)
# Beat schedule for periodic tasks
app.conf.beat_schedule = {
"process-pending-submissions": {
"task": "tasks.workers.process_pending_queue",
"schedule": float(settings.QUEUE_PROCESSOR_INTERVAL), # Every 60 seconds
},
"check-sonauto-credits": {
"task": "tasks.workers.check_credits",
"schedule": float(settings.CREDITS_CHECK_INTERVAL), # Every 10 minutes
},
"check-stale-submissions": {
"task": "tasks.workers.check_timeouts",
"schedule": float(settings.TIMEOUT_CHECK_INTERVAL), # Every 5 minutes
},
"cleanup-old-files": {
"task": "tasks.workers.cleanup_old_files",
"schedule": crontab(hour=3, minute=0), # Daily at 3 AM
},
}
# Auto-discover tasks (module is tasks.workers)
app.autodiscover_tasks(["tasks"], related_name="workers")