feat: deadlock clear

This commit is contained in:
2024-10-22 10:02:26 +03:00
parent 52b3f6e6ee
commit 1806f5dec3
3 changed files with 20 additions and 2 deletions

View File

@@ -26,7 +26,6 @@ class BatchLimiter:
async def acquire(self, key, max_requests, period):
redis = await RedisConnectionManager.get_redis_connection()
while True:
logging.info(f'Getting key: {key}')
async with redis.lock(f"{key}_lock"):
try:
start_time = await redis.get(f"{key}:start_time")
@@ -56,6 +55,13 @@ class BatchLimiter:
logging.error(f"Redis error: {e}")
await asyncio.sleep(1)
async def clear_locks(self):
redis = await RedisConnectionManager.get_redis_connection()
keys = []
async for key in redis.scan_iter('*_lock*'):
keys.append(key)
await redis.delete(*keys)
async def acquire_wildberries(self, key):
max_requests = 300
period = 60