配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
70 lines
1.5 KiB
Python
70 lines
1.5 KiB
Python
"""TOML-backed application configuration singleton and re-export helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.core.app_config_loader import load_app_config
|
|
from app.core.app_config_models import (
|
|
AgentLogConfig,
|
|
AlembicConfig,
|
|
AppConfig,
|
|
AsrConfig,
|
|
CeleryConfig,
|
|
ChatConfig,
|
|
DeployConfig,
|
|
EvalConfig,
|
|
LlmConfig,
|
|
MemoirConfig,
|
|
MemoryConfig,
|
|
MiscConfig,
|
|
OtelConfig,
|
|
StoryConfig,
|
|
TtsConfig,
|
|
)
|
|
from app.core.config import settings as _bootstrap_settings
|
|
|
|
_app_config: AppConfig | None = None
|
|
|
|
|
|
def get_app_config() -> AppConfig:
|
|
global _app_config
|
|
if _app_config is None:
|
|
_app_config = load_app_config(_bootstrap_settings.app_environment)
|
|
return _app_config
|
|
|
|
|
|
def reload_app_config(*, app_environment: str | None = None) -> AppConfig:
|
|
"""Reload TOML config (tests)."""
|
|
global _app_config
|
|
env = app_environment or _bootstrap_settings.app_environment
|
|
_app_config = load_app_config(env)
|
|
return _app_config
|
|
|
|
|
|
class _LazyAppConfig:
|
|
def __getattr__(self, name: str):
|
|
return getattr(get_app_config(), name)
|
|
|
|
|
|
app_config: AppConfig | _LazyAppConfig = _LazyAppConfig()
|
|
|
|
__all__ = [
|
|
"AgentLogConfig",
|
|
"AlembicConfig",
|
|
"AppConfig",
|
|
"AsrConfig",
|
|
"CeleryConfig",
|
|
"ChatConfig",
|
|
"DeployConfig",
|
|
"EvalConfig",
|
|
"LlmConfig",
|
|
"MemoirConfig",
|
|
"MemoryConfig",
|
|
"MiscConfig",
|
|
"OtelConfig",
|
|
"StoryConfig",
|
|
"TtsConfig",
|
|
"app_config",
|
|
"get_app_config",
|
|
"reload_app_config",
|
|
]
|