added bounded cycles for curl_cfii session wedges

This commit is contained in:
TPV committed 2026-07-30 18:57:17 -07:00
1 parent c5fd3efdc5
commit 74f38484ad
1 file changed
+12 -12
+12 -12
View File
@@ -8,12 +8,13 @@ from monitor_utils.constants import CYCLE_DELAY, EXPECTED_TASK_ERRORS
from monitor_utils.database import add_products_to_database from monitor_utils.database import add_products_to_database
from monitor_utils.models import AvailabilityInfo, PricingInfo, Product, ProductMetadata from monitor_utils.models import AvailabilityInfo, PricingInfo, Product, ProductMetadata
from monitor_utils.runner import ( from monitor_utils.runner import (
run_monitor_cycle,
execute_pagination, execute_pagination,
fan_out_group,
init_monitor, init_monitor,
run_bounded_cycle,
setup_monitor_logging, setup_monitor_logging,
) )
from monitor_utils.sessions import get_default_session, send_request from monitor_utils.sessions import send_request
from motor.motor_asyncio import AsyncIOMotorCollection from motor.motor_asyncio import AsyncIOMotorCollection
setup_monitor_logging(monitor_name="samsung_shop") setup_monitor_logging(monitor_name="samsung_shop")
@@ -26,17 +27,16 @@ CATEGORY_SEMAPHORE = asyncio.Semaphore(CATEGORY_CONCURRENCY)
async def main(): async def main():
"""Run the samsung shop monitor loop over all category ids using a base session.""" """Run the samsung shop monitor loop over all category ids on bounded cycles."""
category_paths, collection, proxies = await init_monitor( category_paths, collection, proxies = await init_monitor(
monitor_name="samsung_shop", development_mode=DEVELOPMENT_MODE monitor_name="samsung_shop", development_mode=DEVELOPMENT_MODE
) )
async with get_default_session(proxies) as session:
while True: while True:
await run_monitor_cycle( await run_bounded_cycle(
category_paths, category_paths,
task_func=get_category_products, get_category_products,
session=session, proxies,
collection=collection, collection,
) )
LOGGER.info("tasks completed sleeping", extra={"delay": CYCLE_DELAY}) LOGGER.info("tasks completed sleeping", extra={"delay": CYCLE_DELAY})
await asyncio.sleep(CYCLE_DELAY) await asyncio.sleep(CYCLE_DELAY)
@@ -81,8 +81,10 @@ async def get_category_products(
await process_page(data, category_id, offset, collection) await process_page(data, category_id, offset, collection)
return return
page_task = asyncio.create_task(process_page(data, category_id, offset, collection)) # offset zero owns the fan-out: the group binds this page's processing to the
try: # pagination it spawns, so a cancelled cycle takes both down together.
async with fan_out_group() as group:
group.create_task(process_page(data, category_id, offset, collection))
total_products = data.get("searchTotalCount") total_products = data.get("searchTotalCount")
if total_products is None: if total_products is None:
LOGGER.warning("missing searchTotalCount", extra={"category": category_id}) LOGGER.warning("missing searchTotalCount", extra={"category": category_id})
@@ -98,8 +100,6 @@ async def get_category_products(
category_id=category_id, category_id=category_id,
collection=collection, collection=collection,
) )
finally:
await page_task
async def process_page( async def process_page(