```
refactor(core,ai): 调整模块导入路径并移除废弃文件 - 修复 scheduler.py 中的导入路径错误,将 reports.service 改为 reports.services - 移除废弃的 app/core/background/task_queue.py 文件 - 移除废弃的 app/modules/ai_agent/adapters.py 文件 - 修复 ai_memory/service.py 中的导入路径错误,将 events.service 改为 events.services ```
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
from app.tasks.app import celery_app
|
||||
from app.tasks import events as _events # noqa: F401
|
||||
from app.tasks import legacy as _legacy # noqa: F401
|
||||
from app.tasks import reports as _reports # noqa: F401
|
||||
from app.tasks import risk as _risk # noqa: F401
|
||||
|
||||
|
||||
__all__ = ["celery_app"]
|
||||
@@ -0,0 +1,12 @@
|
||||
from celery import Celery
|
||||
|
||||
from app.core.config import get_settings
|
||||
|
||||
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
|
||||
@@ -0,0 +1,30 @@
|
||||
from socket import gethostname
|
||||
from typing import Any
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import SessionLocal
|
||||
from app.tasks.app import celery_app, settings
|
||||
|
||||
|
||||
@celery_app.task(name="events.dispatch_pending")
|
||||
def dispatch_pending_events(
|
||||
limit: int | None = None,
|
||||
actor: str = ActorValue.WORKER,
|
||||
) -> list[dict[str, Any]]:
|
||||
from app.modules.events.services import EventService
|
||||
from app.modules.observability.constants import HeartbeatComponent
|
||||
from app.modules.observability.service import ObservabilityService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
ObservabilityService(db).record_heartbeat(
|
||||
component=HeartbeatComponent.WORKER,
|
||||
instance_id=gethostname(),
|
||||
actor=actor,
|
||||
)
|
||||
return EventService(db).dispatch_pending(
|
||||
limit=limit or settings.event_dispatch_batch_size,
|
||||
worker_id=f"{actor}:{gethostname()}",
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
@@ -0,0 +1,54 @@
|
||||
from typing import Any
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import SessionLocal
|
||||
from app.tasks.app import celery_app
|
||||
|
||||
|
||||
@celery_app.task(name="legacy.sync_projects")
|
||||
def sync_legacy_projects(
|
||||
source_query: str | None = None,
|
||||
source_query_name: str | None = None,
|
||||
field_map: dict[str, str] | None = None,
|
||||
limit: int = 100,
|
||||
dry_run: bool = False,
|
||||
actor: str = ActorValue.SCHEDULER,
|
||||
) -> dict[str, Any]:
|
||||
from app.modules.legacy_mysql.services import LegacyMySQLService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
return LegacyMySQLService(db).sync_projects(
|
||||
source_query=source_query,
|
||||
source_query_name=source_query_name,
|
||||
field_map=field_map or {},
|
||||
limit=limit,
|
||||
dry_run=dry_run,
|
||||
actor=actor,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
@celery_app.task(name="legacy.sync_tasks")
|
||||
def sync_legacy_tasks(
|
||||
source_query: str | None = None,
|
||||
source_query_name: str | None = None,
|
||||
field_map: dict[str, str] | None = None,
|
||||
limit: int = 100,
|
||||
dry_run: bool = False,
|
||||
actor: str = ActorValue.SCHEDULER,
|
||||
) -> dict[str, Any]:
|
||||
from app.modules.legacy_mysql.services import LegacyMySQLService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
return LegacyMySQLService(db).sync_tasks(
|
||||
source_query=source_query,
|
||||
source_query_name=source_query_name,
|
||||
field_map=field_map or {},
|
||||
limit=limit,
|
||||
dry_run=dry_run,
|
||||
actor=actor,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
@@ -0,0 +1,51 @@
|
||||
from typing import Any
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import SessionLocal
|
||||
from app.modules.feishu.constants import FeishuReceiveIdType
|
||||
from app.tasks.app import celery_app
|
||||
|
||||
|
||||
@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,
|
||||
push_run_code: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
from app.modules.reports.services import ReportService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
report = ReportService(db).daily_brief()
|
||||
return ReportService(db).push_report(
|
||||
report,
|
||||
receive_id,
|
||||
receive_id_type,
|
||||
actor,
|
||||
push_run_code=push_run_code,
|
||||
)
|
||||
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,
|
||||
push_run_code: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
from app.modules.reports.services import ReportService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
report = ReportService(db).project_weekly()
|
||||
return ReportService(db).push_report(
|
||||
report,
|
||||
receive_id,
|
||||
receive_id_type,
|
||||
actor,
|
||||
push_run_code=push_run_code,
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
@@ -0,0 +1,16 @@
|
||||
from typing import Any
|
||||
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import SessionLocal
|
||||
from app.tasks.app import celery_app
|
||||
|
||||
|
||||
@celery_app.task(name="risks.generate_events")
|
||||
def generate_risk_events(actor: str = ActorValue.SCHEDULER) -> dict[str, Any]:
|
||||
from app.modules.risk.services import RiskService
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
return RiskService(db).generate_events(actor=actor)
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user