from typing import Any from celery import Celery from app.core.config import get_settings from app.core.constants import ActorValue from app.core.database import SessionLocal from app.modules.feishu.constants import FeishuReceiveIdType settings = get_settings() celery_app = Celery( "company_ai_platform", broker=settings.redis_url, backend=settings.celery_result_backend_url or settings.redis_url, ) celery_app.conf.task_always_eager = settings.task_queue_always_eager @celery_app.task(name="reports.push_daily_brief") def push_daily_brief( receive_id: str | None = None, receive_id_type: str = FeishuReceiveIdType.CHAT_ID, actor: str = ActorValue.SCHEDULER, ) -> dict[str, Any]: from app.modules.reports.service import ReportService db = SessionLocal() try: report = ReportService(db).daily_brief() return ReportService(db).push_report(report, receive_id, receive_id_type, actor) finally: db.close() @celery_app.task(name="reports.push_project_weekly") def push_project_weekly( receive_id: str | None = None, receive_id_type: str = FeishuReceiveIdType.CHAT_ID, actor: str = ActorValue.SCHEDULER, ) -> dict[str, Any]: from app.modules.reports.service import ReportService db = SessionLocal() try: report = ReportService(db).project_weekly() return ReportService(db).push_report(report, receive_id, receive_id_type, actor) finally: db.close() @celery_app.task(name="risks.generate_events") def generate_risk_events(actor: str = ActorValue.SCHEDULER) -> dict[str, Any]: from app.modules.risk.service import RiskService db = SessionLocal() try: return RiskService(db).generate_events(actor=actor) finally: db.close()