mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
refactor: 重构异步任务系统和计费服务架构
- 重构任务系统:新增 lifecycle (TaskStatus/BillingStatus)、context、application 模块 - 将 video tasks 泛化为 async tasks,支持更通用的异步任务管理 - 新增 Gemini Files 管理模块和管理界面 - 重构 billing 服务:拆分 schema.py 和 service.py - 新增 candidate 服务模块用于请求候选管理 - 数据库迁移:添加 billing_status、request_id、gemini_file_mappings 表和索引 - 移除废弃的 video_telemetry、task orchestrator 等模块
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"""
|
||||
|
||||
from ..models.database import ApiKey, Base, Usage, User, UserQuota
|
||||
from .database import create_session, get_db, get_db_url, init_db, log_pool_status
|
||||
from .database import create_session, get_db, get_db_context, get_db_url, init_db, log_pool_status
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
@@ -12,6 +12,7 @@ __all__ = [
|
||||
"Usage",
|
||||
"UserQuota",
|
||||
"get_db",
|
||||
"get_db_context",
|
||||
"init_db",
|
||||
"create_session",
|
||||
"get_db_url",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import time
|
||||
from collections.abc import Generator
|
||||
from contextlib import contextmanager
|
||||
from typing import Any, cast
|
||||
|
||||
from sqlalchemy import create_engine, event
|
||||
@@ -271,6 +272,31 @@ def create_session() -> Session:
|
||||
return _SessionLocal()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_db_context() -> Generator[Session, None, None]:
|
||||
"""
|
||||
获取数据库会话的上下文管理器
|
||||
|
||||
自动管理会话生命周期:创建、提交/回滚、关闭
|
||||
|
||||
示例:
|
||||
with get_db_context() as db:
|
||||
user = db.query(User).first()
|
||||
# 事务在 with 块结束时自动提交或回滚
|
||||
"""
|
||||
_ensure_engine()
|
||||
assert _SessionLocal is not None
|
||||
db = _SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
db.commit()
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def get_db_url() -> str:
|
||||
"""返回当前配置的数据库连接字符串(供脚本/测试使用)。"""
|
||||
return config.database_url
|
||||
|
||||
Reference in New Issue
Block a user