feat: do not send stocks where disabled

This commit is contained in:
2024-12-06 11:57:40 +03:00
parent 2b5c3966e5
commit cb65e48009
2 changed files with 9 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ class StocksUpdater:
Company.is_archived == False,
Marketplace.is_deleted == False,
Marketplace.is_paused == False,
Marketplace.send_stocks==True,
Marketplace.base_marketplace.in_([
BaseMarketplace.OZON,
BaseMarketplace.WILDBERRIES,
@@ -63,6 +64,8 @@ class StocksUpdater:
async def full_update_marketplace(self, marketplace_id: int):
marketplace = await self.get_marketplace(marketplace_id)
if not marketplace.send_stocks:
return
start = time.time()
updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.update_all()
@@ -97,6 +100,8 @@ class StocksUpdater:
async def update_marketplace_products(self, marketplace_id: int, product_ids: list[int]):
marketplace = await self.get_marketplace(marketplace_id)
if not marketplace.send_stocks:
return
start = time.time()
updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.update_products(product_ids)
@@ -118,6 +123,7 @@ class StocksUpdater:
Company.is_deleted == False,
Company.is_archived == False,
Marketplace.is_paused == False,
Marketplace.send_stocks == True
)
)
stmt_result = await self.session.execute(stmt)
@@ -133,10 +139,10 @@ class StocksUpdater:
tasks.append(self.update_marketplace(marketplace_id, marketplace_updates))
await asyncio.gather(*tasks)
async def reset_marketplace(self, marketplace_id:int):
async def reset_marketplace(self, marketplace_id: int):
marketplace = await self.get_marketplace(marketplace_id)
start = time.time()
updater = UpdaterFactory.get_updater(self.session,marketplace)
updater = UpdaterFactory.get_updater(self.session, marketplace)
await updater.reset()
logging.info(
f"{marketplace.name} successfully updated in {round(time.time() - start, 2)} seconds.")