- 修复 scheduler store 末尾多余逗号 - 将智能体名称从“语析”改为“Kris” - 新增获取运行记录UID的权限校验接口 - 重构操作日志写入逻辑,使用独立会话避免事务污染 - 注册外部系统调度处理器 - 优化全局错误处理器,统一响应格式与序列化处理 - 新增调度任务运行日志的handler_name字段与索引 - 重构任务执行函数,新增payload覆盖与操作人审计参数 - 重写外部系统store,新增侧边栏折叠状态与持久化 - 优化会话、消息等模型的索引、约束与字段类型 - 新增多项配置项与环境变量支持 - 重构渠道相关模型,新增索引、约束与字段优化 - 新增渠道插件模型与内容审核模型的完善
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from fastapi import Request
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from yuxi.storage.postgres.manager import pg_manager
|
|
from yuxi.storage.postgres.models_business import OperationLog
|
|
from yuxi.utils import logger
|
|
|
|
|
|
async def log_operation(
|
|
db: AsyncSession,
|
|
user_id: int | None,
|
|
operation: str,
|
|
details: str | None = None,
|
|
request: Request | None = None,
|
|
) -> None:
|
|
"""记录操作日志。
|
|
|
|
使用独立会话写入日志,避免日志写入失败污染业务会话的事务状态。
|
|
``db`` 参数保留以保持与现有调用方兼容,但实际写入在独立会话中完成。
|
|
"""
|
|
try:
|
|
ip_address = request.client.host if request and request.client else None
|
|
async with pg_manager.get_async_session_context() as session:
|
|
session.add(
|
|
OperationLog(
|
|
user_id=user_id,
|
|
operation=operation,
|
|
details=details,
|
|
ip_address=ip_address,
|
|
)
|
|
)
|
|
except Exception as exc:
|
|
logger.warning(f"操作日志写入失败(不影响主流程): {operation}, user={user_id}, error={exc}")
|