rewritten crap

This commit is contained in:
2025-05-11 08:00:23 +03:00
parent b5110ec69a
commit 2e3245c8f9
8 changed files with 72 additions and 60 deletions

View File

@@ -19,27 +19,29 @@ class WildberriesStocksSender(BaseStocksSender):
return 5
async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
response = await self.api.update_stocks(chunk)
headers = response.headers
status_code = response.status
session,response = await self.api.update_stocks(chunk)
try:
headers = response.headers
status_code = response.status
if status_code in [
401, # Invalid token
403, # Access denied
404, # Not found
400, # Other
]:
return SendStockStatus.ERROR
# If there is rate limit
if status_code == 429:
delay_time = float(headers.get('X-Ratelimit-Reset', self.sleep_time))
await asyncio.sleep(delay_time)
self.remaining = int(headers.get('X-Ratelimit-Limit', 1))
return SendStockStatus.SHOULD_RETRY
self.remaining = int(headers.get('X-Ratelimit-Remaining', 0))
return SendStockStatus.SUCCESS
if status_code in [
401, # Invalid token
403, # Access denied
404, # Not found
400, # Other
]:
return SendStockStatus.ERROR
# If there is rate limit
if status_code == 429:
delay_time = float(headers.get('X-Ratelimit-Reset', self.sleep_time))
await asyncio.sleep(delay_time)
self.remaining = int(headers.get('X-Ratelimit-Limit', 1))
return SendStockStatus.SHOULD_RETRY
self.remaining = int(headers.get('X-Ratelimit-Remaining', 0))
return SendStockStatus.SUCCESS
finally:
await session.close()
async def after_chunk_processed(self):
if self.remaining <= 0:
await asyncio.sleep(self.sleep_time)