fix(platform): 防止绑定任务压垮连接池和事件循环
This commit is contained in:
@@ -14,6 +14,7 @@ from loguru import logger
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
from starlette.concurrency import run_in_threadpool
|
||||
|
||||
from ...models import (
|
||||
Account,
|
||||
@@ -2433,7 +2434,7 @@ def reset_task_binding(
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
async def start_binding(
|
||||
def start_binding_sync(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
@@ -2536,6 +2537,23 @@ async def start_binding(
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
async def start_binding(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
current: User,
|
||||
force_refresh: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""Run the blocking DB/network dispatch path outside the ASGI event loop."""
|
||||
return await run_in_threadpool(
|
||||
start_binding_sync,
|
||||
db,
|
||||
task_id=task_id,
|
||||
current=current,
|
||||
force_refresh=force_refresh,
|
||||
)
|
||||
|
||||
|
||||
def refresh_binding(db: Session, *, task_id: int) -> dict[str, Any]:
|
||||
task = _load_task(db, task_id)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
@@ -2677,7 +2695,7 @@ def reconcile_binding_state_outbox(
|
||||
}
|
||||
|
||||
|
||||
async def confirm_binding(
|
||||
def confirm_binding_sync(
|
||||
db: Session, *, task_id: int, current: User
|
||||
) -> dict[str, Any]:
|
||||
task = _load_task_for_update(db, task_id)
|
||||
@@ -2754,6 +2772,17 @@ async def confirm_binding(
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
async def confirm_binding(
|
||||
db: Session, *, task_id: int, current: User
|
||||
) -> dict[str, Any]:
|
||||
return await run_in_threadpool(
|
||||
confirm_binding_sync,
|
||||
db,
|
||||
task_id=task_id,
|
||||
current=current,
|
||||
)
|
||||
|
||||
|
||||
def refresh_exchange_eligibility(
|
||||
db: Session, *, task_id: int, current: User
|
||||
) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user