Skip to content

Commit bad72e9

Browse files
committed
Depends 제외 (SummaryUC)
1 parent cd10998 commit bad72e9

3 files changed

Lines changed: 54 additions & 32 deletions

File tree

ai_server/DEPLOYMENT_CHECKLIST.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,31 @@ sudo netstat -tlnp | grep 8000
120120
```
121121

122122
### 문제 2: 502 Bad Gateway (nginx)
123-
**원인**: 백엔드 서버 응답 없음
123+
**원인**: 백엔드 서버 응답 없음 (앱 기동 실패 또는 연결 불가)
124124

125125
**해결**:
126126
```bash
127-
# nginx 상태 확인
128-
sudo systemctl status nginx
127+
# 1) Docker 사용 시: 컨테이너 로그에서 기동 실패 원인 확인 (lifespan 예외 등)
128+
docker logs onsikgu-ai-server --tail 200
129+
# 또는
130+
docker compose -f ... logs ai-server --tail 200
131+
132+
# 2) 컨테이너가 재시작 루프인지 확인
133+
docker ps -a # STATUS가 Restarting이면 lifespan/기동 실패 가능성 높음
134+
135+
# 3) 호스트에서 앱 포트 직접 호출 (프록시 제외)
136+
curl -s http://localhost:8000/health # 실패 시 앱 자체 문제
129137

130-
# nginx 로그 확인
138+
# 4) nginx 상태 및 로그
139+
sudo systemctl status nginx
131140
sudo tail -f /var/log/nginx/error.log
132141
```
133142

143+
**자주 나오는 기동 실패 원인**
144+
- `Chroma persist directory is not writable` → 볼륨 경로 `chown 1000:1000` (또는 appuser uid)
145+
- `OPENAI_API_KEY` 누락/오류 → env_file 또는 환경변수 확인
146+
- `get_chroma_collection()` / LLM 초기화 예외 → 위 로그에 traceback 출력됨
147+
134148
### 문제 3: OpenAI API 에러
135149
**원인**: API 키 미설정 또는 잘못된 키
136150

ai_server/app/main.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,42 @@ async def lifespan(app: FastAPI):
3939
# 시작 훅: 첫 요청 전에 의존성(Chroma/체인) 초기화
4040
# - 첫 요청에서 터지지 않게 fail-fast
4141
# - 권한/경로 문제를 부팅 단계에서 바로 발견
42+
# - 실패 시 로그에 전체 traceback 남김 (502 원인 확인: docker logs <container>)
4243
logger.info("[lifespan] startup: initializing dependencies (chroma + generators)")
43-
44-
# Chroma persist directory 쓰기 가능 여부 확인 (권한 이슈 조기 감지)
45-
persist_dir = Path(settings.chroma_persist_directory)
46-
persist_dir.mkdir(parents=True, exist_ok=True)
47-
write_test_path = persist_dir / ".write_test"
4844
try:
49-
write_test_path.write_text("ok", encoding="utf-8")
50-
write_test_path.unlink(missing_ok=True)
51-
except Exception as e:
52-
logger.error(f"[lifespan] chroma persist dir not writable: {persist_dir}", exc_info=True)
53-
raise RuntimeError(f"Chroma persist directory is not writable: {persist_dir}") from e
54-
55-
# DI 싱글톤 생성(초기화) 트리거
56-
from app.presentation.dependencies import (
57-
get_chroma_collection,
58-
get_family_generator,
59-
get_personal_generator,
60-
get_summary_generator,
61-
get_vector_store,
62-
)
63-
64-
get_chroma_collection()
65-
get_vector_store()
66-
get_personal_generator()
67-
get_family_generator()
68-
get_summary_generator()
45+
# Chroma persist directory 쓰기 가능 여부 확인 (권한 이슈 조기 감지)
46+
persist_dir = Path(settings.chroma_persist_directory)
47+
persist_dir.mkdir(parents=True, exist_ok=True)
48+
write_test_path = persist_dir / ".write_test"
49+
try:
50+
write_test_path.write_text("ok", encoding="utf-8")
51+
write_test_path.unlink(missing_ok=True)
52+
except Exception as e:
53+
logger.error(
54+
f"[lifespan] chroma persist dir not writable: {persist_dir}", exc_info=True
55+
)
56+
raise RuntimeError(f"Chroma persist directory is not writable: {persist_dir}") from e
57+
58+
# DI 싱글톤 생성(초기화) 트리거
59+
from app.presentation.dependencies import (
60+
get_chroma_collection,
61+
get_family_generator,
62+
get_personal_generator,
63+
get_summary_generator,
64+
get_vector_store,
65+
)
66+
67+
get_chroma_collection()
68+
get_vector_store()
69+
get_personal_generator()
70+
get_family_generator()
71+
get_summary_generator()
72+
73+
logger.info("[lifespan] startup: initialization complete")
74+
except Exception:
75+
logger.exception("[lifespan] startup failed (502 원인 확인: docker logs <container>)")
76+
raise
6977

70-
logger.info("[lifespan] startup: initialization complete")
7178
yield
7279
logger.info("[lifespan] shutdown")
7380

ai_server/app/presentation/routers/summary_router.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from fastapi import APIRouter, Depends, HTTPException, Query
1212

1313
from app.application.dto.summary_dto import SummaryInput, SummaryOutput
14-
from app.presentation.dependencies import SummaryUC, get_family_summary_use_case
14+
from app.application.use_cases.family_summary import FamilySummaryUseCase
15+
from app.presentation.dependencies import get_family_summary_use_case
1516
from app.presentation.schemas.question_schemas import SummaryResponseSchema
1617

1718
logger = logging.getLogger(__name__)
@@ -32,7 +33,7 @@ async def get_family_summary(
3233
description="weekly(최근 7일) 또는 monthly(최근 30일)",
3334
pattern="^(weekly|monthly)$",
3435
),
35-
use_case: SummaryUC = Depends(get_family_summary_use_case),
36+
use_case: FamilySummaryUseCase = Depends(get_family_summary_use_case),
3637
) -> SummaryResponseSchema:
3738
try:
3839
input_dto = SummaryInput(family_id=familyId, period=period)

0 commit comments

Comments
 (0)