refactor: remove final async blocking query

This commit is contained in:
jxxghp
2026-08-23 23:46:15 +08:00
parent ba2eb869e2
commit 2372b1236e
5 changed files with 61 additions and 5 deletions
+20
View File
@@ -4,6 +4,7 @@ from datetime import datetime
from typing import Optional
from uuid import uuid4
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Session
from app.db.base import DbOper
@@ -66,6 +67,25 @@ class AgentTaskOper(DbOper):
return query(self._db)
return run_sync_transaction(query)
async def async_get(
self,
task_id: int,
user_id: Optional[str] = None,
) -> Optional[AgentTask]:
"""通过异步会话查询单个 Agent 定时任务。"""
async def query(session: AsyncSession) -> Optional[AgentTask]:
"""在调用方异步会话中执行与同步入口相同的查询语义。"""
result = await session.execute(
_get_for_user_statement(
AgentTask,
task_id=task_id,
user_id=user_id,
)
)
return result.scalars().first()
return await self._execute_async_query(query)
def list(
self,
user_id: Optional[str] = None,
+1 -1
View File
@@ -1600,7 +1600,7 @@ class Scheduler(ConfigReloadMixin, metaclass=SingletonClass):
trigger_source=trigger_source,
)
finally:
task = AgentTaskOper().get(task_id)
task = await AgentTaskOper().async_get(task_id)
if task and task.trigger_type == "date" and not task.enabled:
self.remove_agent_task_job(task_id)