"""
Celery application configuration
"""
from celery import Celery
from src.core.config import settings

# Create Celery app instance
celery_app = Celery(
    "bankruptcy_ai_worker",
    broker=settings.CELERY_BROKER_URL,
    backend=settings.CELERY_RESULT_BACKEND,
)

# 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=30 * 60,  # 30 minutes hard limit
    task_soft_time_limit=25 * 60,  # 25 minutes soft limit
    worker_prefetch_multiplier=1,
    worker_max_tasks_per_child=1000,
    task_acks_late=True,
    task_reject_on_worker_lost=True,
    result_expires=3600,  # Results expire after 1 hour
)

# Auto-discover tasks from utils module
celery_app.autodiscover_tasks(['src.utils'], force=True)

if __name__ == "__main__":
    celery_app.start()
