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:
2026-07-09 18:50:52 +08:00
parent dc8605ce3f
commit bf309ecdf7
83 changed files with 4871 additions and 4153 deletions

View File

@@ -0,0 +1,97 @@
from typing import Any
from fastapi import HTTPException, status
from sqlalchemy import select
from app.core.http.pagination import bounded_limit
from app.core.utils.time import utc_now
from app.modules.business.models import (
ReportPushRun,
)
from app.modules.business.service import serialize_model
from app.modules.reports.constants import (
ReportErrorDetail,
ReportPushStatus,
)
from app.modules.reports.services.common import _json_safe, _next_code
class ReportPushRunMixin:
def create_push_run(
self,
report_type: str,
title: str | None,
receive_id: str | None,
receive_id_type: str,
actor: str,
status: str = ReportPushStatus.PENDING,
) -> ReportPushRun:
record = ReportPushRun(
code=_next_code("PUSH"),
report_type=report_type,
title=title,
receive_id=receive_id,
receive_id_type=receive_id_type,
status=status,
actor=actor,
queued_at=utc_now(),
)
self.db.add(record)
self.db.commit()
self.db.refresh(record)
return record
def update_push_run(
self,
code: str,
status: str,
task_id: str | None = None,
provider_response: dict[str, Any] | None = None,
error_message: str | None = None,
sent: bool = False,
) -> ReportPushRun:
record = self._get_push_run(code)
record.status = status
if task_id is not None:
record.task_id = task_id
if provider_response is not None:
record.provider_response = _json_safe(provider_response)
record.error_message = error_message
if sent:
record.sent_at = utc_now()
self.db.commit()
self.db.refresh(record)
return record
def list_push_runs(
self,
status_filter: str | None = None,
limit: int = 100,
) -> list[dict[str, Any]]:
stmt = select(ReportPushRun).order_by(ReportPushRun.id.desc()).limit(
bounded_limit(limit)
)
if status_filter:
stmt = (
select(ReportPushRun)
.where(ReportPushRun.status == status_filter)
.order_by(ReportPushRun.id.desc())
.limit(bounded_limit(limit))
)
return [serialize_model(item) for item in self.db.execute(stmt).scalars()]
def get_push_run(self, code: str) -> dict[str, Any]:
return serialize_model(self._get_push_run(code))
def _get_push_run(self, code: str) -> ReportPushRun:
record = self.db.execute(
select(ReportPushRun).where(ReportPushRun.code == code)
).scalar_one_or_none()
if record is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=ReportErrorDetail.PUSH_RUN_NOT_FOUND,
)
return record