from typing import Any from app.core.background.task_queue.constants import TASK_RUN_LIFECYCLE from app.core.constants import ActorValue from app.core.database import SessionLocal from app.modules.reports.lifecycle_pipeline import LifecyclePipelineService from app.tasks.app import celery_app @celery_app.task( name=TASK_RUN_LIFECYCLE, autoretry_for=(Exception,), retry_backoff=True, retry_kwargs={"max_retries": 3}, ) def run_lifecycle_report( report_type: str, receive_id: str | None = None, receive_id_type: str = "chat_id", force: bool = False, actor: str = ActorValue.SCHEDULER, ) -> dict[str, Any]: db = SessionLocal() try: return LifecyclePipelineService(db).run( report_type, receive_id, receive_id_type, force, actor, ) finally: db.close()