feat: update marketplace products

This commit is contained in:
2024-07-07 21:44:52 +03:00
parent 1bb5c6cbbb
commit 422b24f52d
6 changed files with 40 additions and 2 deletions

View File

@@ -17,6 +17,12 @@ def update_marketplace(marketplace_id: int):
return loop.run_until_complete(background.update.update_marketplace(marketplace_id))
@celery.task(name='update_marketplace_products')
def update_marketplace_products(marketplace_id: int, product_ids: list[int]):
loop = asyncio.get_event_loop()
return loop.run_until_complete(background.update.update_marketplace_products(marketplace_id, product_ids))
@celery.task(name='update_marketplaces')
def update_marketplaces(marketplace_ids: Union[List[int], None]):
loop = asyncio.get_event_loop()

View File

@@ -20,6 +20,14 @@ async def update_marketplace(marketplace_id: int):
return {'message': f'Stocks for marketplace {marketplace_id} successfully updated'}
async def update_marketplace_products(marketplace_id: int, product_ids: list[int]):
async with session_factory() as session:
updater = StocksUpdater(session)
await updater.update_marketplace_products(marketplace_id, product_ids)
return {
'message': f'Products [{",".join(list(map(str, product_ids)))}] successfully updated for marketplace {marketplace_id}'}
async def update_marketplaces(marketplace_ids: Union[List[int], None]):
async with session_factory() as session:
updater = StocksUpdater(session)