mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: govern background tasks and query ownership
This commit is contained in:
@@ -22,6 +22,7 @@ from app.startup.context import (
|
||||
HostRuntime,
|
||||
SubscriptionRuntime,
|
||||
)
|
||||
from app.runtime.tasks import TaskRegistry, get_task_registry
|
||||
|
||||
|
||||
def get_host_runtime(request: Request) -> HostRuntime:
|
||||
@@ -32,6 +33,20 @@ def get_host_runtime(request: Request) -> HostRuntime:
|
||||
return runtime
|
||||
|
||||
|
||||
def get_background_task_registry(
|
||||
runtime: HostRuntime = Depends(get_host_runtime),
|
||||
) -> TaskRegistry:
|
||||
"""返回当前 lifespan 统一管理的后台任务登记器。"""
|
||||
return runtime.tasks
|
||||
|
||||
|
||||
def resolve_background_task_registry(value: object) -> TaskRegistry:
|
||||
"""兼容直接调用 endpoint 的旧入口,并优先使用注入的任务登记器。"""
|
||||
if isinstance(value, TaskRegistry):
|
||||
return value
|
||||
return get_task_registry()
|
||||
|
||||
|
||||
def get_api_runtime_config(
|
||||
runtime: HostRuntime = Depends(get_host_runtime),
|
||||
) -> ApiRuntimeConfig:
|
||||
|
||||
Reference in New Issue
Block a user