rewritten crap

This commit is contained in:
2025-05-11 08:12:26 +03:00
parent 3522c119da
commit 11c128a5a7
4 changed files with 53 additions and 51 deletions

View File

@@ -16,8 +16,9 @@ class OzonStocksSender(BaseStocksSender):
return 100
async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
session ,response = await self.api.update_stocks(data=chunk)
session, response = await self.api.update_stocks(data=chunk)
try:
async with response:
status_code = response.status
if status_code == 200:
return SendStockStatus.SUCCESS
@@ -37,8 +38,8 @@ class OzonStocksSender(BaseStocksSender):
return SendStockStatus.SHOULD_RETRY
return SendStockStatus.ERROR
finally:
await response.close()
await session.close()
async def after_chunk_processed(self):
return await asyncio.sleep(80 / 100)

View File

@@ -19,8 +19,9 @@ class WildberriesStocksSender(BaseStocksSender):
return 5
async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
session,response = await self.api.update_stocks(chunk)
session, response = await self.api.update_stocks(chunk)
try:
async with response:
headers = response.headers
status_code = response.status
@@ -41,8 +42,8 @@ class WildberriesStocksSender(BaseStocksSender):
self.remaining = int(headers.get('X-Ratelimit-Remaining', 0))
return SendStockStatus.SUCCESS
finally:
await response.close()
await session.close()
async def after_chunk_processed(self):
if self.remaining <= 0:
await asyncio.sleep(self.sleep_time)
@@ -52,6 +53,7 @@ class WildberriesStocksSender(BaseStocksSender):
if self.remaining <= 0:
await asyncio.sleep(self.sleep_time)
self.remaining = 1
@property
def chunk_size(self) -> int:
return 1000

View File

@@ -28,6 +28,7 @@ class YandexmarketStocksSender(BaseStocksSender):
async def _process_chunk(self, chunk: list[dict]) -> SendStockStatus:
session, response = await self.api.update_stocks(chunk)
try:
async with response:
status_code = response.status
if status_code == 200:
self.total_stocks_sent += len(chunk)
@@ -40,7 +41,6 @@ class YandexmarketStocksSender(BaseStocksSender):
logging.error(f'[{self.updater.marketplace.id}]: {response_text}')
return SendStockStatus.ERROR
finally:
await response.close()
await session.close()
async def after_chunk_processed(self):

View File

@@ -73,7 +73,6 @@ class BaseMarketplaceUpdater(ABC):
return {}
async def filter_stocks_data(self, stock_data_list: list[StockData]) -> list[StockData]:
return stock_data_list
cached_stocks: dict = await self.redis_client.hgetall(self.get_cache_key())
cached_stocks = {int(k): int(v) for k, v in cached_stocks.items()}
result = []