v1.0
This commit is contained in:
@@ -45,6 +45,8 @@ class OzonMarketplaceApi(BaseMarketplaceApi):
|
|||||||
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_ozon(self.limiter_key)
|
await limiter.acquire_ozon(self.limiter_key)
|
||||||
request_data = {'stocks': chunk}
|
request_data = {'stocks': chunk}
|
||||||
@@ -55,9 +57,11 @@ 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
|
||||||
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
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ class WildberriesMarketplaceApi(BaseMarketplaceApi):
|
|||||||
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}
|
||||||
@@ -59,9 +61,11 @@ 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
|
||||||
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
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class YandexmarketMarketplaceApi(BaseMarketplaceApi):
|
|||||||
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 = {
|
||||||
@@ -57,9 +59,11 @@ 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
|
||||||
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
|
||||||
|
|
||||||
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
tasks = [send_stock_chunk(chunk) for chunk in chunks]
|
||||||
await asyncio.gather(*tasks)
|
await asyncio.gather(*tasks)
|
||||||
|
|||||||
Reference in New Issue
Block a user