From 3a30758a71e1cbe7d9e4e0793dc613c294d764a6 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 16 Nov 2025 21:00:58 +0300 Subject: [PATCH] fix: wb secret token --- background/tasks.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/background/tasks.py b/background/tasks.py index 6e42cce..e908e0e 100644 --- a/background/tasks.py +++ b/background/tasks.py @@ -1,8 +1,14 @@ +import asyncio import logging +from sqlalchemy import select + import background.update +from backend.session import get_session from background.broker import taskiq_broker from buffer.core import TasksBuffer +from database import Marketplace, Company +from utils import chunk_list @taskiq_broker.task(task_name='process_update') @@ -50,3 +56,28 @@ async def flush_buffer(): logging.info(f'Buffer flushed with {total_products} products') except Exception as 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) +