Phase 28: P3 — Pydantic Settings, dependency-injector IoC, tenacity retry

- config.py: dataclasses → pydantic-settings BaseSettings (flat AppConfig,
  env vars auto-loaded from .env, type-safe validation)
- api_client.py: HTTPAPIClient takes AppConfig directly (APIConfig removed);
  tenacity retry on 5 methods (reset/ingest/list/delete/feedback) —
  retries on 5xx + TransportError, 3 attempts, exponential backoff 1-8s
- container.py: manual DI → dependency_injector DeclarativeContainer with
  providers.Singleton; Container() needs no args
- app.py: container.X → container.X() calls, remove AppConfig import
- requirements.txt: add pydantic-settings, tenacity, dependency-injector

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sal
2026-06-02 05:59:23 +09:00
parent 148211e236
commit 974bab7cd8
6 changed files with 67 additions and 70 deletions
+5 -4
View File
@@ -13,8 +13,8 @@
| async/sync 혼용 | ~~`asyncio.run()` 5곳~~ → 모든 콜백 async 전환 완료 | ✅ 완료 |
| 코드 중복 | ~~`asyncio.run()` 5회 반복~~ → container 위임으로 제거 | ✅ 완료 |
| 결합도 | ~~`api_client` 직접 임포트~~ → DI container + Protocol 추상화 | ✅ 완료 |
| 테스트 가능성 | Protocol 도입으로 모킹 가능 테스트 작성 | 🟡 중간 |
| 로깅 | `print()` 만 사용 | 🟢 낮음 |
| 테스트 가능성 | ~~모킹 가능~~ → pytest-asyncio 단위 테스트 10개 작성 | ✅ 완료 |
| 로깅 | ~~`print()` 만 사용~~`logging` 모듈, `LOG_LEVEL` 환경변수 | ✅ 완료 |
---
@@ -303,5 +303,6 @@ youlbot-webui/
- [x] `tests/` 단위 테스트 작성 — `pytest-asyncio`, `ChatService` 4개 / `DocumentService` 6개 (10/10 통과)
### P3
- [ ] 재시도 로직
- [ ] Pydantic Settings
- [x] 재시도 로직 — `tenacity` / 5xx·TransportError에만 최대 3회, 지수 백오프(1→8s) / `chat` 제외 5개 메서드 적용
- [x] Pydantic Settings — `config.py` dataclass → `BaseSettings` (flat `AppConfig`), `.env` 자동 로드
- [x] IoC 프레임워크 전환 — 수동 DI → `dependency-injector` `DeclarativeContainer` + `providers.Singleton`