mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-07 00:16:57 +08:00
refactor: 收敛 factory 模块级副作用并统一 async 路径进度为异步后端
- 将 configure_token_codec/configure_plugin_routes 移入 create_app(),消除 import 期副作用 - runtime 层新增 AsyncCacheProxy/AsyncTTLCache/AsyncProgressHelper,共享 progress region - search/system/history/scheduler/dashboard 的事件循环路径切换异步进度后端 - 同步进度回调经事件循环提交或线程池执行,避免阻塞事件循环
This commit is contained in:
@@ -2,6 +2,7 @@ from pathlib import Path
|
||||
from typing import Any, List, Optional, Annotated
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
|
||||
from app.schemas.dashboard import DashboardMemoryInfo as _SchemaDashboardMemoryInfo
|
||||
from app.schemas.dashboard import DashboardSystemInfo as _SchemaDashboardSystemInfo
|
||||
@@ -160,7 +161,8 @@ async def schedule(_: Any = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
查询后台服务信息
|
||||
"""
|
||||
return Scheduler().list()
|
||||
# 同步 list() 内含同步进度读取,放到线程池执行避免阻塞事件循环
|
||||
return await run_in_threadpool(Scheduler().list)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -174,7 +176,8 @@ async def schedule_progress(
|
||||
"""
|
||||
查询指定后台服务的执行进度。
|
||||
"""
|
||||
progress = Scheduler().get_progress(job_id)
|
||||
# 异步进度后端读取,避免同步 Redis 调用阻塞事件循环
|
||||
progress = await Scheduler().aget_progress(job_id)
|
||||
if not progress:
|
||||
return _SchemaResponse(success=False, message="后台服务不存在")
|
||||
return _SchemaResponse(success=True, data=progress.model_dump())
|
||||
@@ -189,7 +192,8 @@ async def schedule2(_: Annotated[str, Depends(verify_apitoken)]) -> Any:
|
||||
"""
|
||||
查询下载器信息 API_TOKEN认证(?token=xxx)
|
||||
"""
|
||||
return Scheduler().list()
|
||||
# 同步 list() 内含同步进度读取,放到线程池执行避免阻塞事件循环
|
||||
return await run_in_threadpool(Scheduler().list)
|
||||
|
||||
|
||||
@router.get(
|
||||
@@ -203,7 +207,8 @@ async def schedule_progress2(
|
||||
"""
|
||||
查询指定后台服务的执行进度 API_TOKEN认证(?token=xxx)
|
||||
"""
|
||||
progress = Scheduler().get_progress(job_id)
|
||||
# 异步进度后端读取,避免同步 Redis 调用阻塞事件循环
|
||||
progress = await Scheduler().aget_progress(job_id)
|
||||
if not progress:
|
||||
return _SchemaResponse(success=False, message="后台服务不存在")
|
||||
return _SchemaResponse(success=True, data=progress.model_dump())
|
||||
|
||||
Reference in New Issue
Block a user