fixed small pagination issue in execute_pagination/added availability field in mongo schema

This commit is contained in:
TPV committed 2026-07-14 12:02:07 -07:00
1 parent ae8b204a2c
commit f2e50819ac
3 files changed
+14 -5

No files matched your search

+1
View File
@@ -346,6 +346,7 @@ def convert_product_to_mongo(product: Product) -> dict:
"priceBeforeDrop": pricing["price_before_drop"], "priceBeforeDrop": pricing["price_before_drop"],
"eduPrice": pricing["edu_price"], "eduPrice": pricing["edu_price"],
"available": availability["available"], "available": availability["available"],
"availabilityLastChecked": availability["availability_last_checked"],
"condition": availability["condition"], "condition": availability["condition"],
"appExclusive": availability["app_exclusive"], "appExclusive": availability["app_exclusive"],
"memberPick": availability["member_pick"], "memberPick": availability["member_pick"],
+3
View File
@@ -54,6 +54,8 @@ class AvailabilityInfo:
app_exclusive: Only purchasable through the retailer's app. app_exclusive: Only purchasable through the retailer's app.
member_pick: Flagged as a member pick offer. member_pick: Flagged as a member pick offer.
member_deal: Flagged as a member deal offer. member_deal: Flagged as a member deal offer.
availability_last_checked: When available was last verified against
the retailer, letting monitors skip rechecks within an interval.
""" """
available: bool | None = None available: bool | None = None
@@ -61,6 +63,7 @@ class AvailabilityInfo:
app_exclusive: bool | None = None app_exclusive: bool | None = None
member_pick: bool | None = None member_pick: bool | None = None
member_deal: bool | None = None member_deal: bool | None = None
availability_last_checked: datetime | None = None
@dataclass @dataclass
+10 -5
View File
@@ -84,7 +84,9 @@ async def init_monitor(
async def setup_config( async def setup_config(
monitor_name: str, development_mode: DevelopmentMode monitor_name: str, development_mode: DevelopmentMode
) -> tuple[list[str] | dict[str, str], dict[str, str | list[str]], AsyncIOMotorCollection]: ) -> tuple[
list[str] | dict[str, str], dict[str, str | list[str]], AsyncIOMotorCollection
]:
"""Load monitor config and resolve the Mongo collection for the mode. """Load monitor config and resolve the Mongo collection for the mode.
Testing mode reads the configs_testing collection and appends a _testing Testing mode reads the configs_testing collection and appends a _testing
@@ -275,14 +277,15 @@ async def execute_pagination(
session: aiohttp.ClientSession | AsyncSession, session: aiohttp.ClientSession | AsyncSession,
*, *,
max_concurrent_tasks: int = 5, max_concurrent_tasks: int = 5,
start_offset: int = 24, start_offset: int = 0,
pagination_mode: str = "offset", pagination_mode: str = "offset",
**kwargs, **kwargs,
): ):
"""Paginate a category by dispatching concurrent page or offset tasks to func. """Paginate a category by dispatching concurrent page or offset tasks to func.
Runs pages 2..N under a semaphore, retries failed pages with exponential Runs pages 2..N under a semaphore, retries failed pages with exponential
backoff, and logs any pages that still fail after retries. backoff, and logs any pages that still fail after retries. Page 1 is
assumed to have been fetched by the caller.
Args: Args:
category_identifier: Label used for logging only; not passed to func. category_identifier: Label used for logging only; not passed to func.
@@ -292,7 +295,9 @@ async def execute_pagination(
offset or page_number depending on pagination_mode. offset or page_number depending on pagination_mode.
session: HTTP session forwarded to each func call. session: HTTP session forwarded to each func call.
max_concurrent_tasks: Semaphore limit for concurrent page fetches. max_concurrent_tasks: Semaphore limit for concurrent page fetches.
start_offset: Base offset added when pagination_mode is offset. start_offset: Additive base applied to every offset, for APIs whose
offset space does not begin at zero. Page N requests offset
start_offset + (N - 1) * products_per_page.
pagination_mode: Either offset or page, selecting the kwarg sent to func. pagination_mode: Either offset or page, selecting the kwarg sent to func.
**kwargs: Forwarded verbatim to every func call. Any identifier func **kwargs: Forwarded verbatim to every func call. Any identifier func
needs (category_id, category_name, category_path, or bestbuy's needs (category_id, category_name, category_path, or bestbuy's
@@ -317,7 +322,7 @@ async def execute_pagination(
return return
if pagination_mode == "offset": if pagination_mode == "offset":
current_offset = start_offset + page_index * products_per_page current_offset = start_offset + (page_index - 1) * products_per_page
await func( await func(
session=session, session=session,
offset=current_offset, offset=current_offset,