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

@@ -26,18 +26,21 @@ class YandexmarketStocksSender(BaseStocksSender):
return 2000
async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
response = await self.api.update_stocks(chunk)
status_code = response.status
if status_code == 200:
self.total_stocks_sent += len(chunk)
return SendStockStatus.SUCCESS
if status_code == 420:
time_to_sleep = 60 - (time.time() - self.start_time)
await asyncio.sleep(time_to_sleep)
return SendStockStatus.SHOULD_RETRY
response_text = await response.text()
logging.error(f'[{self.updater.marketplace.id}]: {response_text}')
return SendStockStatus.ERROR
session, response = await self.api.update_stocks(chunk)
try:
status_code = response.status
if status_code == 200:
self.total_stocks_sent += len(chunk)
return SendStockStatus.SUCCESS
if status_code == 420:
time_to_sleep = 60 - (time.time() - self.start_time)
await asyncio.sleep(time_to_sleep)
return SendStockStatus.SHOULD_RETRY
response_text = await response.text()
logging.error(f'[{self.updater.marketplace.id}]: {response_text}')
return SendStockStatus.ERROR
finally:
await session.close()
async def after_chunk_processed(self):
time_delta = time.time() - self.start_time