aiteamutils 0.2.39__tar.gz → 0.2.41__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiteamutils
3
- Version: 0.2.39
3
+ Version: 0.2.41
4
4
  Summary: AI Team Utilities
5
5
  Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
6
  Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
@@ -685,16 +685,33 @@ class DatabaseService:
685
685
 
686
686
  Returns:
687
687
  생성된 로그 엔티티
688
- """
689
- # 공통 필드 추가 (ULID를 문자열로 변환)
690
- log_data["ulid"] = str(ULID())
691
-
692
- # request가 있는 경우 user-agent와 ip 정보 추가
693
- if request:
694
- log_data["user_agent"] = request.headers.get("user-agent")
695
- log_data["ip_address"] = request.headers.get("x-forwarded-for")
696
688
 
697
- return await self.create_entity(model, log_data)
689
+ Raises:
690
+ CustomException: 로그 생성 실패 시
691
+ """
692
+ try:
693
+ # 공통 필드 추가 (ULID를 문자열로 변환)
694
+ log_data["ulid"] = str(ULID())
695
+
696
+ # request가 있는 경우 user-agent와 ip 정보 추가
697
+ if request:
698
+ log_data["user_agent"] = request.headers.get("user-agent")
699
+ log_data["ip_address"] = request.headers.get("x-forwarded-for")
700
+
701
+ # 데이터 전처리
702
+ processed_data = self.preprocess_data(model, log_data)
703
+ entity = model(**processed_data)
704
+
705
+ # 로그 엔티티 저장
706
+ self.db.add(entity)
707
+ await self.db.flush()
708
+
709
+ return entity
710
+
711
+ except Exception as e:
712
+ logging.error(f"Failed to create log: {str(e)}")
713
+ # 로그 생성 실패는 원래 작업에 영향을 주지 않도록 함
714
+ return None
698
715
 
699
716
  async def soft_delete(
700
717
  self,
@@ -99,35 +99,15 @@ def get_service(name: str):
99
99
  """
100
100
  def _get_service(db_service: DatabaseService = Depends(get_database_service)):
101
101
  try:
102
- # 서비스 레지스트리에서 클래스 조회
103
- try:
104
- repository_class, service_class = service_registry.get(name)
105
- except CustomException as e:
106
- raise CustomException(
107
- ErrorCode.SERVICE_NOT_REGISTERED,
108
- detail=f"Service '{name}' is not registered",
109
- source_function="dependencies.get_service",
110
- original_error=e
111
- )
112
-
113
- # 서비스 인스턴스 생성
114
- try:
115
- repository = repository_class(db_service)
116
- return service_class(repository)
117
- except Exception as e:
118
- raise CustomException(
119
- ErrorCode.INTERNAL_ERROR,
120
- detail=f"Failed to create service instance for '{name}': {str(e)}",
121
- source_function="dependencies.get_service",
122
- original_error=e
123
- )
124
-
102
+ repository_class, service_class = service_registry.get(name)
103
+ repository = repository_class(db_service)
104
+ return service_class(repository, db_service)
125
105
  except CustomException as e:
126
106
  raise e
127
107
  except Exception as e:
128
108
  raise CustomException(
129
109
  ErrorCode.INTERNAL_ERROR,
130
- detail=f"Unexpected error while creating service '{name}': {str(e)}",
110
+ detail=f"Failed to create service '{name}': {str(e)}",
131
111
  source_function="dependencies.get_service",
132
112
  original_error=e
133
113
  )
@@ -0,0 +1,2 @@
1
+ """버전 정보"""
2
+ __version__ = "0.2.41"
@@ -1,2 +0,0 @@
1
- """버전 정보"""
2
- __version__ = "0.2.39"
@@ -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