checkpoint: require_redis 显式 503 守卫——存储类接口(AI配置/在线/缓存/验证码)接线
- dependencies: require_redis 改标准 FastAPI 依赖(Depends(redis_getter)),Redis 不可用显式 503 而非 500/静默空数据 - AI配置 5 端点 / 在线监控 5 端点 / 缓存监控 6 端点切到 require_redis - 免认证验证码端点(captcha/get、slider/complete)也接线:Redis 挂时返回 503 而非 500 - login/token/oauth 保留 redis_getter(服务层内联 503 守卫语义不变)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
from collections.abc import AsyncGenerator
|
||||
from typing import Any
|
||||
from typing import Annotated, Any
|
||||
|
||||
from fastapi import Depends, Request
|
||||
from redis.asyncio.client import Redis
|
||||
@@ -39,12 +39,12 @@ async def redis_getter(request: Request) -> Redis:
|
||||
return request.app.state.redis
|
||||
|
||||
|
||||
def require_redis(redis: Redis | None) -> Redis:
|
||||
async def require_redis(redis: Annotated[Redis | None, Depends(redis_getter)]) -> Redis:
|
||||
"""Redis 不可用时显式 503(存储类接口守卫)。
|
||||
|
||||
Redis 是认证会话、AI 模型配置、在线监控与调度任务 jobstore 的唯一存储。
|
||||
启动降级模式下这些接口无法提供服务,应明确返回 503,而非误导性的
|
||||
401/500 或静默空数据。
|
||||
Redis 是认证会话、AI 模型配置、在线监控存储的唯一存储(调度任务 jobstore 已落 PG)。
|
||||
存储类接口应依赖本守卫(而非裸 redis_getter):降级模式下明确返回 503,
|
||||
而不是 500/401 或静默空数据;免认证接口(如验证码)读 Redis 时也由此兜底。
|
||||
"""
|
||||
if redis is None:
|
||||
raise CustomException(
|
||||
|
||||
Reference in New Issue
Block a user