755ecc9abe
- 删除 .gitlab-ci.yml - 删除 runtime_config.py 兼容层 - Pydantic Settings + YAML 三层配置分离 - 统一 PlatformConfigLoader 加载器 - docker-compose 移除重复 environment 覆盖 - volcengine base_url 从 YAML 读取 - 微信支付/SMS 空值启动时拦截 - 日志仅输出控制台,不写文件 - 更新 model_router 注释
88 lines
2.4 KiB
Python
88 lines
2.4 KiB
Python
"""
|
|
系统模块 API
|
|
============
|
|
"""
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, status
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.core.health_checker import check_database, check_redis
|
|
from app.schemas.common import ApiResponse, success_response
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=ApiResponse[dict])
|
|
async def system_health():
|
|
"""系统健康检查(详细版)"""
|
|
db_ok, db_msg = await check_database()
|
|
redis_ok, redis_msg = await check_redis()
|
|
|
|
services = {
|
|
"api": "up",
|
|
"database": "connected" if db_ok else db_msg,
|
|
"redis": "connected" if redis_ok else redis_msg,
|
|
}
|
|
|
|
if not db_ok:
|
|
return JSONResponse(
|
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
content={
|
|
"code": status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
"message": "数据库连接异常",
|
|
"data": {"status": "unhealthy", "services": services},
|
|
},
|
|
)
|
|
|
|
if not redis_ok:
|
|
return success_response(
|
|
message="Redis 连接异常,服务降级",
|
|
data={"status": "degraded", "services": services},
|
|
)
|
|
|
|
return success_response(
|
|
message="系统运行正常",
|
|
data={"status": "healthy", "services": services},
|
|
)
|
|
|
|
|
|
@router.get("/version", response_model=ApiResponse[dict])
|
|
async def system_version():
|
|
"""获取系统版本信息"""
|
|
from app.config import get_settings
|
|
|
|
settings = get_settings()
|
|
|
|
return success_response(
|
|
data={
|
|
"name": settings.APP_NAME,
|
|
"version": settings.APP_VERSION,
|
|
"environment": settings.ENV,
|
|
},
|
|
message="获取版本成功",
|
|
)
|
|
|
|
|
|
@router.post("/admin/runtime-config/reload", response_model=ApiResponse[dict])
|
|
async def reload_runtime_config_api():
|
|
"""
|
|
❌ 已禁用 — 所有环境均不支持热重载配置。
|
|
|
|
测试/生产环境统一走 Docker 滚动重启:
|
|
docker compose -f docker-compose.prod.yml up -d --build
|
|
|
|
Python 模块导入机制导致运行时热替换配置是反模式,
|
|
不区分环境,一律禁止。
|
|
"""
|
|
return JSONResponse(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
content={
|
|
"code": status.HTTP_403_FORBIDDEN,
|
|
"message": "热重载已禁用,请使用滚动重启更新配置",
|
|
"data": None,
|
|
},
|
|
)
|