redis-allocator 0.4.0__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- __version__ = '0.4.0'
1
+ __version__ = '0.4.1'
@@ -257,14 +257,14 @@ class RedisAllocatorUpdater:
257
257
  return len(self.params)
258
258
 
259
259
 
260
- class RedisAllocatorPolicy(ABC):
260
+ class RedisAllocatorPolicy(ABC, Generic[U]):
261
261
  """Abstract base class for Redis allocator policies.
262
262
 
263
263
  This class defines the interface for allocation policies that can be used
264
264
  with RedisAllocator to control allocation behavior.
265
265
  """
266
266
 
267
- def initialize(self, allocator: 'RedisAllocator'):
267
+ def initialize(self, allocator: 'RedisAllocator[U]'):
268
268
  """Initialize the policy with an allocator instance.
269
269
 
270
270
  Args:
@@ -273,9 +273,9 @@ class RedisAllocatorPolicy(ABC):
273
273
  pass
274
274
 
275
275
  @abstractmethod
276
- def malloc(self, allocator: 'RedisAllocator', timeout: Timeout = 120,
277
- obj: Optional[Any] = None, params: Optional[dict] = None,
278
- cache_timeout: Timeout = 3600) -> Optional[RedisAllocatorObject]:
276
+ def malloc(self, allocator: 'RedisAllocator[U]', timeout: Timeout = 120,
277
+ obj: Optional[U] = None, params: Optional[dict] = None,
278
+ cache_timeout: Timeout = 3600) -> Optional[RedisAllocatorObject[U]]:
279
279
  """Allocate a resource according to the policy.
280
280
 
281
281
  Args:
@@ -292,7 +292,7 @@ class RedisAllocatorPolicy(ABC):
292
292
  pass
293
293
 
294
294
  @abstractmethod
295
- def refresh_pool(self, allocator: 'RedisAllocator'):
295
+ def refresh_pool(self, allocator: 'RedisAllocator[U]'):
296
296
  """Refresh the allocation pool.
297
297
 
298
298
  This method is called periodically to update the pool with new resources.
@@ -302,7 +302,7 @@ class RedisAllocatorPolicy(ABC):
302
302
  """
303
303
  pass
304
304
 
305
- def check_health_once(self, r_obj: RedisAllocatorObject, duration: int = 3600) -> bool:
305
+ def check_health_once(self, r_obj: RedisAllocatorObject[U], duration: int = 3600) -> bool:
306
306
  """Check the health of the object."""
307
307
  with contextlib.closing(r_obj.open()):
308
308
  try:
@@ -318,8 +318,8 @@ class RedisAllocatorPolicy(ABC):
318
318
  r_obj.set_unhealthy(duration)
319
319
  raise
320
320
 
321
- def check_health(self, allocator: 'RedisAllocator', lock_duration: Timeout = 3600, max_threads: int = 8,
322
- obj_fn: Optional[Callable[[str], Any]] = None,
321
+ def check_health(self, allocator: 'RedisAllocator[U]', lock_duration: Timeout = 3600, max_threads: int = 8,
322
+ obj_fn: Optional[Callable[[str], U]] = None,
323
323
  params_fn: Optional[Callable[[str], dict]] = None) -> tuple[int, int]:
324
324
  """Check the health of the allocator.
325
325
 
@@ -349,7 +349,7 @@ class RedisAllocatorPolicy(ABC):
349
349
  return healthy, unhealthy
350
350
 
351
351
 
352
- class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
352
+ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy[U]):
353
353
  """Default implementation of RedisAllocatorPolicy.
354
354
 
355
355
  This policy provides the following features:
@@ -393,7 +393,7 @@ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
393
393
  self.objects: weakref.WeakValueDictionary[str, RedisAllocatorObject] = weakref.WeakValueDictionary()
394
394
  self.auto_close = auto_close
395
395
 
396
- def initialize(self, allocator: 'RedisAllocator'):
396
+ def initialize(self, allocator: 'RedisAllocator[U]'):
397
397
  """Initialize the policy with an allocator instance.
398
398
 
399
399
  Args:
@@ -403,9 +403,9 @@ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
403
403
  self._update_lock_key = f"{allocator._pool_str()}|policy_update_lock"
404
404
  atexit.register(lambda: self.finalize(self._allocator()))
405
405
 
406
- def malloc(self, allocator: 'RedisAllocator', timeout: Timeout = 120,
407
- obj: Optional[Any] = None, params: Optional[dict] = None,
408
- cache_timeout: Timeout = 3600) -> Optional[RedisAllocatorObject]:
406
+ def malloc(self, allocator: 'RedisAllocator[U]', timeout: Timeout = 120,
407
+ obj: Optional[U] = None, params: Optional[dict] = None,
408
+ cache_timeout: Timeout = 3600) -> Optional[RedisAllocatorObject[U]]:
409
409
  """Allocate a resource according to the policy.
410
410
 
411
411
  This implementation:
@@ -445,7 +445,7 @@ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
445
445
  return alloc_obj
446
446
 
447
447
  @cached(TTLCache(maxsize=64, ttl=5))
448
- def _try_refresh_pool(self, allocator: 'RedisAllocator'):
448
+ def _try_refresh_pool(self, allocator: 'RedisAllocator[U]'):
449
449
  """Try to refresh the pool if necessary and if we can acquire the lock.
450
450
 
451
451
  Args:
@@ -457,7 +457,7 @@ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
457
457
  # If we got here, we acquired the lock, so we can update the pool
458
458
  self.refresh_pool(allocator)
459
459
 
460
- def refresh_pool(self, allocator: 'RedisAllocator'):
460
+ def refresh_pool(self, allocator: 'RedisAllocator[U]'):
461
461
  """Refresh the allocation pool using the updater.
462
462
 
463
463
  Args:
@@ -478,7 +478,7 @@ class DefaultRedisAllocatorPolicy(RedisAllocatorPolicy):
478
478
  else:
479
479
  allocator.extend(keys, timeout=self.expiry_duration)
480
480
 
481
- def finalize(self, allocator: 'RedisAllocator'):
481
+ def finalize(self, allocator: 'RedisAllocator[U]'):
482
482
  """Finalize the policy."""
483
483
  for obj in self.objects.values():
484
484
  obj.close()
@@ -521,7 +521,7 @@ class RedisAllocator(RedisLockPool, Generic[U]):
521
521
  """
522
522
 
523
523
  def __init__(self, redis: Redis, prefix: str, suffix='allocator', eps=1e-6,
524
- shared=False, policy: Optional[RedisAllocatorPolicy] = None):
524
+ shared=False, policy: Optional[RedisAllocatorPolicy[U]] = None):
525
525
  """Initializes the RedisAllocator.
526
526
 
527
527
  Args:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: redis-allocator
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Redis-based resource allocation system.
5
5
  Home-page: https://github.com/invoker-bot/RedisAllocator-python
6
6
  Author: Invoker Bot
@@ -1,15 +1,15 @@
1
1
  redis_allocator/__init__.py,sha256=TVjUm-8YEu_MQD_PkfeIKiVknpCJBrUY9cWN1LlaZcU,1016
2
- redis_allocator/_version.py,sha256=2eiWQI55fd-roDdkt4Hvl9WzrTJ4xQo33VzFud6D03U,22
3
- redis_allocator/allocator.py,sha256=Bo4Ck7mqg-Z8KdQH-iqeHfdEbyhMqBD0c2g5T3E5sBU,48730
2
+ redis_allocator/_version.py,sha256=qBs4HqYsPn6yUHWEuCN4rGUC05gABbl800d8LBd8h9w,22
3
+ redis_allocator/allocator.py,sha256=AerjK6B5-qaAsMn_ivJjRSn4GXWop27x4UDc1rlKP34,48778
4
4
  redis_allocator/lock.py,sha256=fqf6WUWHKYenEArWopMIF6kWEnDfADC-bZvnQImsQVo,27400
5
5
  redis_allocator/task_queue.py,sha256=8DjNr2uxhzCsHatV_CHOeGh7_K9pqQZFApSbe2blRO0,14989
6
- redis_allocator-0.4.0.dist-info/licenses/LICENSE,sha256=Wt4X1rHpffQfEiyWcDUx8BMLjXxfPqaiYZ7Lgsj7L4c,1068
6
+ redis_allocator-0.4.1.dist-info/licenses/LICENSE,sha256=Wt4X1rHpffQfEiyWcDUx8BMLjXxfPqaiYZ7Lgsj7L4c,1068
7
7
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  tests/conftest.py,sha256=Ts82uylQSzP_GcaN0E02o3xcFdjw20cXNzh3RAdYKW4,3967
9
9
  tests/test_allocator.py,sha256=hFKgLe_yONtEjjm6zssUnhK0tzihG_1xZMziztHmqqA,22404
10
10
  tests/test_lock.py,sha256=MDMRNN46VhWqkHUIhYOMEDgZkFFCW_WjwRLTOjkFF-Q,46952
11
11
  tests/test_task_queue.py,sha256=Fh5naikFajfOvL6GngEy_TPfOYCYZolZfVwtR6T4dTY,31710
12
- redis_allocator-0.4.0.dist-info/METADATA,sha256=rXeA3Nsb6eie8H5G10HXLlLI8jCRs45I1C06seN-Sgs,21727
13
- redis_allocator-0.4.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
14
- redis_allocator-0.4.0.dist-info/top_level.txt,sha256=0hXzU7sK5FCeSolTEYxThOt3HOybnwaXv1FLRJvHVgI,22
15
- redis_allocator-0.4.0.dist-info/RECORD,,
12
+ redis_allocator-0.4.1.dist-info/METADATA,sha256=K0lLGpDplwpwCMMuzUiA8CkkRfTPAIyswx4anbo0O-Y,21727
13
+ redis_allocator-0.4.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
14
+ redis_allocator-0.4.1.dist-info/top_level.txt,sha256=0hXzU7sK5FCeSolTEYxThOt3HOybnwaXv1FLRJvHVgI,22
15
+ redis_allocator-0.4.1.dist-info/RECORD,,