mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 07:56:52 +08:00
chore: sync database worker branch with upstream v3
This commit is contained in:
@@ -13,7 +13,9 @@ from app.runtime.capabilities.model import (
|
||||
SelectorSchema,
|
||||
)
|
||||
from app.runtime.capabilities.registry import CapabilityRegistry
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.extensions.service_config import ServiceConfigHelper
|
||||
from app.schemas.types import (
|
||||
DownloaderType,
|
||||
|
||||
@@ -12,7 +12,9 @@ from app.runtime.capabilities.model import (
|
||||
CapabilitySpec,
|
||||
)
|
||||
from app.runtime.capabilities.runtime import CapabilityRuntime
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.events import Event, EventHandlerBinding, eventmanager
|
||||
from app.runtime.extensions.host_module_adapter import (
|
||||
HOST_MODULE_KIND,
|
||||
|
||||
@@ -7,7 +7,9 @@ from collections.abc import Callable, Mapping
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.foundation.version import compare_version
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.extensions.plugin.contracts import supports_plugin_hook
|
||||
from app.runtime.extensions.plugin.storage import PluginStorage
|
||||
from app.runtime.extensions.plugin.system import PluginSystemServices
|
||||
|
||||
@@ -15,7 +15,9 @@ from app.foundation.singleton import Singleton
|
||||
from app.foundation.version import compare_version
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.observability import observe_compat_facade
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.events import EventHandlerBinding, eventmanager
|
||||
from app.runtime.reload import ConfigReloadMixin
|
||||
from app.runtime.extensions.plugin.loader import PluginLoader
|
||||
|
||||
+44
-6
@@ -9,24 +9,63 @@ from typing import Any
|
||||
|
||||
RuntimeSettingProvider = Callable[[str], Any]
|
||||
_provider: RuntimeSettingProvider | None = None
|
||||
_runtime_settings_service: Any | None = None
|
||||
# 测试和插件可能临时替换某个模块上的 importlib.import_module;保存原始函数,
|
||||
# 让兼容代理的 legacy Settings 解析不受这类局部替身影响。
|
||||
_import_module = importlib.import_module
|
||||
|
||||
|
||||
class RuntimeSettingsCompat:
|
||||
"""为旧模块级 Settings 访问提供动态 runtime 配置代理。"""
|
||||
|
||||
@staticmethod
|
||||
def _legacy_settings() -> Any:
|
||||
"""返回旧 Settings 实例,供 runtime 尚未装配时的兼容回退使用。"""
|
||||
return _import_module("app.runtime.config").settings
|
||||
|
||||
def __getattr__(self, key: str) -> Any:
|
||||
"""读取当前组合根配置;未装配时沿用旧 Settings 回退。"""
|
||||
return get_runtime_setting(key)
|
||||
|
||||
def __setattr__(self, key: str, value: Any) -> None:
|
||||
"""把旧模块级覆盖同步到 legacy Settings,保持测试和插件注入语义。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
setattr(legacy_settings, key, value)
|
||||
setattr(self._legacy_settings(), key, value)
|
||||
|
||||
def __delattr__(self, key: str) -> None:
|
||||
"""删除旧模块级覆盖,使配置对象恢复其原有属性解析。"""
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
delattr(legacy_settings, key)
|
||||
delattr(self._legacy_settings(), key)
|
||||
|
||||
def model_dump(
|
||||
self,
|
||||
*,
|
||||
include: set[str] | None = None,
|
||||
exclude: set[str] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> dict[str, Any]:
|
||||
"""导出当前配置快照,保留旧 Settings 的序列化入口。"""
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.snapshot(include=include, exclude=exclude)
|
||||
return self._legacy_settings().model_dump(
|
||||
include=include, exclude=exclude, **kwargs
|
||||
)
|
||||
|
||||
def update_setting(self, key: str, value: Any) -> tuple[Any, str]:
|
||||
"""更新单项配置,兼容插件对模块级 Settings 的公开调用。"""
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.update(key, value)
|
||||
return self._legacy_settings().update_setting(key, value)
|
||||
|
||||
def update_settings(self, env: dict[str, Any]) -> dict[str, tuple[Any, str]]:
|
||||
"""批量更新配置,兼容旧 Settings 的管理接口。"""
|
||||
if _runtime_settings_service is not None:
|
||||
return _runtime_settings_service.update_many(env)
|
||||
return self._legacy_settings().update_settings(env=env)
|
||||
|
||||
|
||||
def configure_runtime_settings_compat(service: Any) -> None:
|
||||
"""由应用组合根注入可变配置服务,避免低层代理反向导入应用层。"""
|
||||
global _runtime_settings_service
|
||||
_runtime_settings_service = service
|
||||
|
||||
|
||||
def configure_runtime_setting_provider(provider: RuntimeSettingProvider) -> None:
|
||||
@@ -39,5 +78,4 @@ def get_runtime_setting(key: str) -> Any:
|
||||
"""读取单项运行配置;启动早期未装配时回退旧 Settings ABI。"""
|
||||
if _provider is not None:
|
||||
return _provider(key)
|
||||
legacy_settings = importlib.import_module("app.runtime.config").settings
|
||||
return getattr(legacy_settings, key)
|
||||
return getattr(RuntimeSettingsCompat._legacy_settings(), key)
|
||||
|
||||
@@ -11,7 +11,9 @@ from typing import Optional, Tuple
|
||||
import docker
|
||||
import psutil
|
||||
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.runtime.log import logger
|
||||
from app.runtime.reload import ConfigReloadMixin
|
||||
from app.foundation.environment import is_docker
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from contextvars import copy_context
|
||||
|
||||
from app.runtime.config import settings
|
||||
from app.runtime.settings import RuntimeSettingsCompat
|
||||
|
||||
settings = RuntimeSettingsCompat()
|
||||
from app.foundation.singleton import Singleton
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user