"""Celery application configuration.""" import os from celery import Celery # Get configuration from environment variables CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0") CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0") # Configure Celery celery_app = Celery( "yottob", broker=CELERY_BROKER_URL, backend=CELERY_RESULT_BACKEND, include=["download_service", "scheduled_tasks"] ) # Celery configuration celery_app.conf.update( task_serializer="json", accept_content=["json"], result_serializer="json", timezone="UTC", enable_utc=True, task_track_started=True, task_time_limit=3600, # 1 hour max per task task_soft_time_limit=3300, # 55 minutes soft limit worker_prefetch_multiplier=1, # Process one task at a time worker_max_tasks_per_child=50, # Restart worker after 50 tasks beat_schedule={ "cleanup-old-videos-daily": { "task": "download_service.cleanup_old_videos", "schedule": 86400.0, # Run every 24 hours (in seconds) }, }, ) # Scheduled tasks from celery.schedules import crontab celery_app.conf.beat_schedule = { "check-latest-videos-midnight": { "task": "scheduled_tasks.check_and_download_latest_videos", "schedule": crontab(minute=0, hour=0), # Run at midnight UTC }, }