aiteamutils 0.2.40__tar.gz → 0.2.42__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/PKG-INFO +1 -1
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/database.py +59 -11
- aiteamutils-0.2.42/aiteamutils/version.py +2 -0
- aiteamutils-0.2.40/aiteamutils/version.py +0 -2
- aiteamutils-0.2.40/startup.py +0 -54
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/.cursorrules +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/.gitignore +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/README.md +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/dependencies.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/security.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/pyproject.toml +0 -0
- {aiteamutils-0.2.40 → aiteamutils-0.2.42}/setup.py +0 -0
@@ -47,8 +47,21 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
47
47
|
CustomException: 세션 생성 실패 시
|
48
48
|
"""
|
49
49
|
db_service = get_database_service()
|
50
|
+
if not db_service or not db_service.engine:
|
51
|
+
raise CustomException(
|
52
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
53
|
+
detail="Database service or engine is not properly initialized",
|
54
|
+
source_function="get_db"
|
55
|
+
)
|
56
|
+
|
50
57
|
try:
|
51
58
|
async with db_service.get_session() as session:
|
59
|
+
if session is None:
|
60
|
+
raise CustomException(
|
61
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
62
|
+
detail="Failed to create database session",
|
63
|
+
source_function="get_db"
|
64
|
+
)
|
52
65
|
yield session
|
53
66
|
except Exception as e:
|
54
67
|
raise CustomException(
|
@@ -58,7 +71,7 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
58
71
|
original_error=e
|
59
72
|
)
|
60
73
|
finally:
|
61
|
-
if 'session' in locals():
|
74
|
+
if 'session' in locals() and session is not None:
|
62
75
|
await session.close()
|
63
76
|
|
64
77
|
def get_database_session(db: AsyncSession = Depends(get_db)) -> 'DatabaseService':
|
@@ -69,8 +82,26 @@ def get_database_session(db: AsyncSession = Depends(get_db)) -> 'DatabaseService
|
|
69
82
|
|
70
83
|
Returns:
|
71
84
|
DatabaseService: DatabaseService 인스턴스
|
85
|
+
|
86
|
+
Raises:
|
87
|
+
CustomException: 데이터베이스 세션이 유효하지 않은 경우
|
72
88
|
"""
|
73
|
-
|
89
|
+
if db is None:
|
90
|
+
raise CustomException(
|
91
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
92
|
+
detail="Database session is not initialized",
|
93
|
+
source_function="get_database_session"
|
94
|
+
)
|
95
|
+
|
96
|
+
db_service = DatabaseService(session=db)
|
97
|
+
if db_service.db is None:
|
98
|
+
raise CustomException(
|
99
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
100
|
+
detail="Failed to initialize database session",
|
101
|
+
source_function="get_database_session"
|
102
|
+
)
|
103
|
+
|
104
|
+
return db_service
|
74
105
|
|
75
106
|
class DatabaseService:
|
76
107
|
def __init__(
|
@@ -685,16 +716,33 @@ class DatabaseService:
|
|
685
716
|
|
686
717
|
Returns:
|
687
718
|
생성된 로그 엔티티
|
688
|
-
"""
|
689
|
-
# 공통 필드 추가 (ULID를 문자열로 변환)
|
690
|
-
log_data["ulid"] = str(ULID())
|
691
719
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
720
|
+
Raises:
|
721
|
+
CustomException: 로그 생성 실패 시
|
722
|
+
"""
|
723
|
+
try:
|
724
|
+
# 공통 필드 추가 (ULID를 문자열로 변환)
|
725
|
+
log_data["ulid"] = str(ULID())
|
726
|
+
|
727
|
+
# request가 있는 경우 user-agent와 ip 정보 추가
|
728
|
+
if request:
|
729
|
+
log_data["user_agent"] = request.headers.get("user-agent")
|
730
|
+
log_data["ip_address"] = request.headers.get("x-forwarded-for")
|
731
|
+
|
732
|
+
# 데이터 전처리
|
733
|
+
processed_data = self.preprocess_data(model, log_data)
|
734
|
+
entity = model(**processed_data)
|
735
|
+
|
736
|
+
# 로그 엔티티 저장
|
737
|
+
self.db.add(entity)
|
738
|
+
await self.db.flush()
|
739
|
+
|
740
|
+
return entity
|
741
|
+
|
742
|
+
except Exception as e:
|
743
|
+
logging.error(f"Failed to create log: {str(e)}")
|
744
|
+
# 로그 생성 실패는 원래 작업에 영향을 주지 않도록 함
|
745
|
+
return None
|
698
746
|
|
699
747
|
async def soft_delete(
|
700
748
|
self,
|
aiteamutils-0.2.40/startup.py
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
async def startup_event() -> None:
|
2
|
-
"""Application startup event handler."""
|
3
|
-
try:
|
4
|
-
# 1. 설정 및 DB 초기화
|
5
|
-
init_settings(
|
6
|
-
jwt_secret=settings.JWT_SECRET,
|
7
|
-
jwt_algorithm=settings.JWT_ALGORITHM,
|
8
|
-
db_url=settings.CORE_DB_URL,
|
9
|
-
db_echo=settings.DB_ECHO,
|
10
|
-
db_pool_size=settings.DB_POOL_SIZE,
|
11
|
-
db_max_overflow=settings.DB_MAX_OVERFLOW,
|
12
|
-
db_pool_timeout=settings.DB_POOL_TIMEOUT,
|
13
|
-
db_pool_recycle=settings.DB_POOL_RECYCLE
|
14
|
-
)
|
15
|
-
db_service = get_database_service()
|
16
|
-
|
17
|
-
if not db_service or not db_service.engine:
|
18
|
-
raise RuntimeError("데이터베이스 서비스 초기화 실패")
|
19
|
-
|
20
|
-
# 2. DB 연결 테스트
|
21
|
-
async with db_service.engine.begin() as conn:
|
22
|
-
await conn.run_sync(lambda _: None)
|
23
|
-
logging.info("데이터베이스 연결 성공")
|
24
|
-
|
25
|
-
# 3. 테이블 생성
|
26
|
-
async with db_service.engine.begin() as conn:
|
27
|
-
await conn.run_sync(Base.metadata.create_all)
|
28
|
-
logging.info("데이터베이스 테이블 생성 완료")
|
29
|
-
|
30
|
-
# 4. 서비스 등록
|
31
|
-
register_services()
|
32
|
-
service_registry.set_initialized() # 서비스 등록 완료 표시
|
33
|
-
|
34
|
-
logging.info("서비스 등록 완료")
|
35
|
-
|
36
|
-
except Exception as e:
|
37
|
-
logging.error(f"애플리케이션 시작 실패: {str(e)}")
|
38
|
-
raise RuntimeError(f"애플리케이션 시작 실패: {str(e)}")
|
39
|
-
|
40
|
-
async def shutdown_event() -> None:
|
41
|
-
"""Application shutdown event handler."""
|
42
|
-
try:
|
43
|
-
# 1. 서비스 레지스트리 초기화
|
44
|
-
service_registry.clear()
|
45
|
-
logging.info("서비스 레지스트리 초기화 완료")
|
46
|
-
|
47
|
-
# 2. 데이터베이스 연결 종료
|
48
|
-
db_service = get_database_service()
|
49
|
-
if db_service and db_service.engine:
|
50
|
-
await db_service.engine.dispose()
|
51
|
-
logging.info("데이터베이스 연결 종료")
|
52
|
-
except Exception as e:
|
53
|
-
logging.error(f"애플리케이션 종료 중 오류 발생: {str(e)}")
|
54
|
-
raise
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|