fix: wb secret token
This commit is contained in:
@@ -1,8 +1,14 @@
|
|||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from sqlalchemy import select
|
||||||
|
|
||||||
import background.update
|
import background.update
|
||||||
|
from backend.session import get_session
|
||||||
from background.broker import taskiq_broker
|
from background.broker import taskiq_broker
|
||||||
from buffer.core import TasksBuffer
|
from buffer.core import TasksBuffer
|
||||||
|
from database import Marketplace, Company
|
||||||
|
from utils import chunk_list
|
||||||
|
|
||||||
|
|
||||||
@taskiq_broker.task(task_name='process_update')
|
@taskiq_broker.task(task_name='process_update')
|
||||||
@@ -50,3 +56,28 @@ async def flush_buffer():
|
|||||||
logging.info(f'Buffer flushed with {total_products} products')
|
logging.info(f'Buffer flushed with {total_products} products')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f'Error in flush_buffer: {e}')
|
logging.error(f'Error in flush_buffer: {e}')
|
||||||
|
|
||||||
|
|
||||||
|
@taskiq_broker.task(schedule=[{"cron": "0 */3 * * *"}])
|
||||||
|
async def reset_companies_with_zero_balance():
|
||||||
|
logging.info(f'Flushing zero balance companies')
|
||||||
|
async for session in get_session():
|
||||||
|
marketplaces_stmt = (
|
||||||
|
select(
|
||||||
|
Marketplace
|
||||||
|
)
|
||||||
|
.join(
|
||||||
|
Company
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
Company.balance <= 45,
|
||||||
|
Company.is_deleted == False,
|
||||||
|
Company.is_archived == False,
|
||||||
|
Marketplace.is_deleted == False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
marketplaces = list((await session.scalars(marketplaces_stmt)).all())
|
||||||
|
for marketplaces_chunk in chunk_list(marketplaces, 10):
|
||||||
|
tasks = [background.update.reset_marketplace(marketplace.id) for marketplace in marketplaces_chunk]
|
||||||
|
await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user