v1.0
This commit is contained in:
@@ -42,11 +42,11 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
|||||||
return
|
return
|
||||||
max_stocks = 100
|
max_stocks = 100
|
||||||
chunks = utils.chunk_list(data, max_stocks)
|
chunks = utils.chunk_list(data, max_stocks)
|
||||||
|
if not chunks:
|
||||||
|
return
|
||||||
limiter = BatchLimiter()
|
limiter = BatchLimiter()
|
||||||
|
|
||||||
async def send_stock_chunk(chunk):
|
async def send_stock_chunk(chunk) -> bool:
|
||||||
if not self.is_valid:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
await limiter.acquire_ozon(self.limiter_key)
|
await limiter.acquire_ozon(self.limiter_key)
|
||||||
request_data = {'stocks': chunk}
|
request_data = {'stocks': chunk}
|
||||||
@@ -57,11 +57,18 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
|||||||
if error_message:
|
if error_message:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f'Error occurred when sending stocks to [{self.marketplace.id}]: {error_message} ({error_code})')
|
f'Error occurred when sending stocks to [{self.marketplace.id}]: {error_message} ({error_code})')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
first_request = tasks[0]
|
||||||
|
first_response = await first_request
|
||||||
|
if not first_response:
|
||||||
|
logging.error(f'Skipping marketplace [{self.marketplace.id}] because first request was unsuccessful')
|
||||||
|
return
|
||||||
|
|
||||||
|
await asyncio.gather(*tasks[1:])
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ class WildberriesMarketplaceApi(BaseMarketplaceApi):
|
|||||||
return
|
return
|
||||||
max_stocks = 1000
|
max_stocks = 1000
|
||||||
chunks = utils.chunk_list(data, max_stocks)
|
chunks = utils.chunk_list(data, max_stocks)
|
||||||
|
if not chunks:
|
||||||
|
return
|
||||||
limiter = BatchLimiter()
|
limiter = BatchLimiter()
|
||||||
|
|
||||||
async def send_stock_chunk(chunk):
|
async def send_stock_chunk(chunk):
|
||||||
if not self.is_valid:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
await limiter.acquire_wildberries(self.limiter_key)
|
await limiter.acquire_wildberries(self.limiter_key)
|
||||||
request_data = {'stocks': chunk}
|
request_data = {'stocks': chunk}
|
||||||
@@ -61,11 +61,17 @@ class WildberriesMarketplaceApi(BaseMarketplaceApi):
|
|||||||
error_code = response.get('code')
|
error_code = response.get('code')
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f'Error occurred when sending stocks to [{self.marketplace.id}]: {error_message} ({error_code})')
|
f'Error occurred when sending stocks to [{self.marketplace.id}]: {error_message} ({error_code})')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
first_request = tasks[0]
|
||||||
|
first_response = await first_request
|
||||||
|
if not first_response:
|
||||||
|
logging.error(f'Skipping marketplace [{self.marketplace.id}] because first request was unsuccessful')
|
||||||
|
return
|
||||||
|
|
||||||
|
await asyncio.gather(*tasks[1:])
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ class YandexmarketMarketplaceApi(BaseMarketplaceApi):
|
|||||||
campaign_id = self.marketplace.campaign_id
|
campaign_id = self.marketplace.campaign_id
|
||||||
max_stocks = 2000
|
max_stocks = 2000
|
||||||
chunks = chunk_list(data, max_stocks)
|
chunks = chunk_list(data, max_stocks)
|
||||||
|
if not chunks:
|
||||||
|
return
|
||||||
limiter = BatchLimiter()
|
limiter = BatchLimiter()
|
||||||
|
|
||||||
async def send_stock_chunk(chunk):
|
async def send_stock_chunk(chunk):
|
||||||
if not self.is_valid:
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
await limiter.acquire_yandexmarket(self.limiter_key)
|
await limiter.acquire_yandexmarket(self.limiter_key)
|
||||||
request_data = {
|
request_data = {
|
||||||
@@ -59,11 +59,18 @@ class YandexmarketMarketplaceApi(BaseMarketplaceApi):
|
|||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
f'Error occurred when sending stocks to [{self.marketplace.id}]')
|
f'Error occurred when sending stocks to [{self.marketplace.id}]')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(
|
logging.error(
|
||||||
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
f'Exception occurred while sending stocks to marketplace ID [{self.marketplace.id}]: {str(e)}')
|
||||||
self.is_valid = False
|
return False
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
first_request = tasks[0]
|
||||||
|
first_response = await first_request
|
||||||
|
if not first_response:
|
||||||
|
logging.error(f'Skipping marketplace [{self.marketplace.id}] because first request was unsuccessful')
|
||||||
|
return
|
||||||
|
|
||||||
|
await asyncio.gather(*tasks[1:])
|
||||||
|
|||||||
Reference in New Issue
Block a user