This commit is contained in:
2024-07-03 08:11:08 +03:00
parent 7ba3426989
commit c9ddfaf8b4
17 changed files with 751 additions and 42 deletions

View File

@@ -1,14 +1,27 @@
import time
from typing import Union, List
from backend.session import get_session
from backend.session import session_factory
from schemas.general import StockUpdate
from updaters.stocks_updater import StocksUpdater
async def process_update(product_ids: list[int]):
async for session in get_session():
async with session_factory() as session:
updates = [StockUpdate(product_id=product_id) for product_id in product_ids]
updater = StocksUpdater(session)
await updater.update(updates)
await session.close()
return {'message': f'Stocks for [{",".join(map(str, product_ids))}] successfully updated'}
return {'message': f'Stocks for products [{",".join(map(str, product_ids))}] successfully updated'}
async def update_marketplace(marketplace_id: int):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.full_update_marketplace(marketplace_id)
return {'message': f'Stocks for marketplace {marketplace_id} successfully updated'}
async def update_marketplaces(marketplace_ids: Union[List[int], None]):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.full_update_all_marketplaces(marketplace_ids)
return {'message': f'Stocks for marketplaces [{",".join(map(str, marketplace_ids))}] successfully updated'}