feat(api): DB off degraded 기동(store 폴백) + dev 인증 우회 — 풀 API 라이브 E2E 통과
- main lifespan: init_pool 실패해도 store 인메모리 폴백으로 degraded 기동 - deps: environment=dev면 쿠키 없어도 더미 학습자(로컬 라이브). prod는 401 유지 - 실증: POST /sessions(201) → turn → 서연 client_reply, safety_flagged=false
This commit is contained in:
parent
eca1f6a413
commit
c57c34ade6
2 changed files with 21 additions and 7 deletions
|
|
@ -63,10 +63,12 @@ async def get_current_principal(
|
||||||
prod 에선 session_cookie 검증 실패 시 무조건 401.
|
prod 에선 session_cookie 검증 실패 시 무조건 401.
|
||||||
"""
|
"""
|
||||||
if not session_cookie:
|
if not session_cookie:
|
||||||
raise HTTPException(
|
# dev 환경에선 쿠키 없어도 더미 학습자로 통과(로컬 라이브 테스트). prod 는 무조건 401.
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
if get_settings().environment != "dev":
|
||||||
detail="not authenticated",
|
raise HTTPException(
|
||||||
)
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="not authenticated",
|
||||||
|
)
|
||||||
# TODO: Redis 세션 룩업. 아래는 개발 스텁.
|
# TODO: Redis 세션 룩업. 아래는 개발 스텁.
|
||||||
return Principal(user_id="dev-user", role=Role.LEARNER, cohort_ids=[])
|
return Principal(user_id="dev-user", role=Role.LEARNER, cohort_ids=[])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,26 @@ from .routes import voice as voice_routes
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
"""startup: DB 풀 + 엔진 클라이언트 / shutdown: 정리."""
|
"""startup: DB 풀 + 엔진 클라이언트 / shutdown: 정리.
|
||||||
await init_pool()
|
|
||||||
|
DB 미가용(Docker off / NAS 연결불가)이면 store 인메모리 폴백으로 degraded 기동한다.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
await init_pool()
|
||||||
|
except Exception as exc: # DB 없어도 store 폴백으로 1턴 동작 (dev/로컬)
|
||||||
|
import logging
|
||||||
|
logging.getLogger("uvicorn.error").warning(
|
||||||
|
"DB 풀 초기화 실패 — store 인메모리 폴백으로 degraded 기동: %s", exc
|
||||||
|
)
|
||||||
await engine_client.startup()
|
await engine_client.startup()
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
await engine_client.shutdown()
|
await engine_client.shutdown()
|
||||||
await close_pool()
|
try:
|
||||||
|
await close_pool()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue