aiteamutils 0.2.36__tar.gz → 0.2.37__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.36
3
+ Version: 0.2.37
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
@@ -15,6 +15,9 @@ from .config import get_settings
15
15
 
16
16
  pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
17
17
 
18
+ # 전역 rate limit 상태 저장
19
+ _rate_limits: Dict[str, Dict[str, Any]] = {}
20
+
18
21
  class RateLimitExceeded(CustomException):
19
22
  """Rate limit 초과 예외."""
20
23
 
@@ -200,14 +203,10 @@ def rate_limit(
200
203
  key_func: Optional[Callable] = None
201
204
  ):
202
205
  """Rate limiting 데코레이터."""
203
- rate_limits: Dict[str, Dict[str, Any]] = {}
204
-
205
206
  def decorator(func: Callable) -> Callable:
206
207
  @wraps(func)
207
208
  async def wrapper(*args, **kwargs):
208
209
  logging.info(f"[rate_limit] Starting rate limit check for {func.__name__}")
209
- logging.info(f"[rate_limit] Args: {args}")
210
- logging.info(f"[rate_limit] Kwargs: {kwargs}")
211
210
 
212
211
  # Request 객체 찾기
213
212
  request = None
@@ -240,16 +239,16 @@ def rate_limit(
240
239
  now = datetime.now(UTC)
241
240
 
242
241
  # 현재 rate limit 정보 가져오기
243
- rate_info = rate_limits.get(rate_limit_key)
242
+ rate_info = _rate_limits.get(rate_limit_key)
244
243
  logging.info(f"[rate_limit] Current rate info: {rate_info}")
245
244
 
246
245
  if rate_info is None or (now - rate_info["start_time"]).total_seconds() >= window_seconds:
247
246
  # 새로운 rate limit 설정
248
- rate_limits[rate_limit_key] = {
247
+ _rate_limits[rate_limit_key] = {
249
248
  "count": 1,
250
249
  "start_time": now
251
250
  }
252
- logging.info(f"[rate_limit] Created new rate limit: {rate_limits[rate_limit_key]}")
251
+ logging.info(f"[rate_limit] Created new rate limit: {_rate_limits[rate_limit_key]}")
253
252
  else:
254
253
  # 기존 rate limit 업데이트
255
254
  if rate_info["count"] >= max_requests:
@@ -268,14 +267,6 @@ def rate_limit(
268
267
 
269
268
  try:
270
269
  logging.info(f"[rate_limit] Executing original function: {func.__name__}")
271
- # db_service가 있는지 확인
272
- for arg in args:
273
- if hasattr(arg, 'db_service'):
274
- logging.info(f"[rate_limit] Found db_service in args: {arg.db_service}")
275
- for value in kwargs.values():
276
- if hasattr(value, 'db_service'):
277
- logging.info(f"[rate_limit] Found db_service in kwargs: {value.db_service}")
278
-
279
270
  result = await func(*args, **kwargs)
280
271
  logging.info("[rate_limit] Function executed successfully")
281
272
  return result
@@ -290,7 +281,7 @@ def rate_limit(
290
281
  source_function=func.__name__,
291
282
  original_error=e
292
283
  )
293
-
284
+
294
285
  return wrapper
295
286
  return decorator
296
287
 
@@ -0,0 +1,2 @@
1
+ """버전 정보"""
2
+ __version__ = "0.2.37"
@@ -1,2 +0,0 @@
1
- """버전 정보"""
2
- __version__ = "0.2.36"
File without changes
File without changes
File without changes
File without changes