refactor: finish transactional runtime migration

This commit is contained in:
jxxghp
2026-08-22 15:18:16 +08:00
parent fe2e6809f7
commit be18cace1f
59 changed files with 1006 additions and 568 deletions
+16 -1
View File
@@ -1,6 +1,6 @@
"""从 FastAPI AppState 读取类型化宿主能力。"""
from collections.abc import AsyncGenerator
from collections.abc import AsyncGenerator, Generator
from typing import cast
from fastapi import Depends, Request
@@ -39,6 +39,21 @@ def get_api_runtime_config(
return runtime.configuration.api()
def get_sync_session(
runtime: HostRuntime = Depends(get_host_runtime),
) -> Generator[object, None, None]:
"""从 HostRuntime 生成请求独占的同步数据库会话。"""
yield from runtime.persistence.sync_session()
async def get_async_session(
runtime: HostRuntime = Depends(get_host_runtime),
) -> AsyncGenerator[object, None]:
"""从 HostRuntime 生成请求独占的异步数据库会话。"""
async for session in runtime.persistence.async_session():
yield session
def resolve_api_runtime_config(value: object) -> ApiRuntimeConfig:
"""兼容直接调用 endpoint 的旧入口,并统一返回真实配置快照。"""
if isinstance(value, ApiRuntimeConfig):