mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
refactor: 移除 Python 后端源码,全面迁移至 Rust gateway 架构
- 删除全部 Python 源码 (src/) 及 Alembic 迁移脚本,归档至 _deprecated_py_src/ - 重构 Rust gateway ai_pipeline: 拆分 planner/finalize 模块,新增 contracts/adaptation 层 - 重组 handlers 模块为 admin/public/proxy/internal/shared 子模块结构 - 新增 executor 模块,引入 Rust 原生数据库迁移 (aether-data/migrations) - 简化 CI/Docker 构建流程,移除 base image 二级构建,统一为单一 app image - 移除 Python 相关基础设施文件 (entrypoint.sh, gunicorn_conf.py, Dockerfile.base)
This commit is contained in:
75
_deprecated_py_src/services/task/submit/attempt.py
Normal file
75
_deprecated_py_src/services/task/submit/attempt.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.services.billing.rule_service import BillingRuleLookupResult
|
||||
from src.services.candidate.submit import SubmitOutcome
|
||||
from src.services.task.submit.record import AsyncSubmitRecordService
|
||||
from src.services.task.submit.response import AsyncSubmitResponseService
|
||||
|
||||
|
||||
class AsyncSubmitAttemptService:
|
||||
"""异步提交单候选执行编排服务。"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
db: Session,
|
||||
*,
|
||||
sanitize: Callable[[str], str],
|
||||
extract_response_text: Callable[[httpx.Response], str],
|
||||
match_provider_failover_rule: Callable[..., str | None],
|
||||
) -> None:
|
||||
self.db = db
|
||||
self._record_ops = AsyncSubmitRecordService(db)
|
||||
self._response_ops = AsyncSubmitResponseService(
|
||||
db,
|
||||
record_ops=self._record_ops,
|
||||
sanitize=sanitize,
|
||||
extract_response_text=extract_response_text,
|
||||
match_provider_failover_rule=match_provider_failover_rule,
|
||||
)
|
||||
|
||||
async def submit_candidate(
|
||||
self,
|
||||
*,
|
||||
candidate: Any,
|
||||
record_id: str | None,
|
||||
candidate_info: dict[str, Any],
|
||||
candidate_keys: list[dict[str, Any]],
|
||||
rule_lookup: BillingRuleLookupResult | None,
|
||||
submit_func: Any,
|
||||
extract_external_task_id: Any,
|
||||
) -> tuple[SubmitOutcome | None, int | None]:
|
||||
self._record_ops.mark_pending(record_id=record_id)
|
||||
|
||||
# Flush/commit BEFORE awaiting upstream submit to avoid holding DB connections.
|
||||
if self.db.in_transaction():
|
||||
try:
|
||||
self.db.commit()
|
||||
except Exception:
|
||||
self.db.rollback()
|
||||
raise
|
||||
|
||||
# Attempt submit (upstream HTTP)
|
||||
try:
|
||||
response: httpx.Response = await submit_func(candidate)
|
||||
except Exception as exc:
|
||||
return self._response_ops.handle_submit_exception(
|
||||
record_id=record_id,
|
||||
candidate_info=candidate_info,
|
||||
exc=exc,
|
||||
)
|
||||
|
||||
return self._response_ops.handle_submit_response(
|
||||
candidate=candidate,
|
||||
record_id=record_id,
|
||||
candidate_info=candidate_info,
|
||||
candidate_keys=candidate_keys,
|
||||
rule_lookup=rule_lookup,
|
||||
response=response,
|
||||
extract_external_task_id=extract_external_task_id,
|
||||
)
|
||||
Reference in New Issue
Block a user