""" Celery worker for MyDocManager document processing tasks. This module contains all Celery tasks for processing documents. """ import asyncio import os from celery import Celery from tasks.document_processing import process_document_async # Environment variables REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0") MONGODB_URL = os.getenv("MONGODB_URL", "mongodb://localhost:27017") # Initialize Celery app celery_app = Celery( "mydocmanager_worker", broker=REDIS_URL, backend=REDIS_URL, ) # 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=300, # 5 minutes task_soft_time_limit=240, # 4 minutes ) @celery_app.task(bind=True, autoretry_for=(Exception,), retry_kwargs={'max_retries': 3, 'countdown': 60}) def process_document(self, filepath: str): return asyncio.run(process_document_async(self, filepath)) if __name__ == "__main__": celery_app.start()