FIXXXXX
This commit is contained in:
1 parent
30b4b26c9e
commit
535826fce6
2 files changed
+17
-7
No files matched your search
+9
-3
@@ -16,11 +16,12 @@ Throttler = throttler.GlobalThrottler
|
|||||||
LEGO_CAT_ID = get_sq_env.LEGO_CAT_ID
|
LEGO_CAT_ID = get_sq_env.LEGO_CAT_ID
|
||||||
|
|
||||||
|
|
||||||
async def enrich_single_item(item_id: str, logger=None) -> bool:
|
async def enrich_single_item(item_id: str, item_data: dict = None, logger=None) -> bool:
|
||||||
r"""
|
r"""
|
||||||
|
Enrich a single Square catalog item with Brickset data.
|
||||||
|
|
||||||
Flow:
|
Flow:
|
||||||
1. Get item details from Square (by item_id)
|
1. Get item details from Square (by item_id) - skip if item_data provided
|
||||||
2. Extract 5-digit set number from name (regex \d{5})
|
2. Extract 5-digit set number from name (regex \d{5})
|
||||||
3. Fetch Brickset data (with throttling)
|
3. Fetch Brickset data (with throttling)
|
||||||
4. Update Square item with enriched data
|
4. Update Square item with enriched data
|
||||||
@@ -28,6 +29,7 @@ async def enrich_single_item(item_id: str, logger=None) -> bool:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
item_id: Square catalog item ID
|
item_id: Square catalog item ID
|
||||||
|
item_data: Optional pre-fetched item data (avoids redundant API call)
|
||||||
logger: Optional logger instance for debug output
|
logger: Optional logger instance for debug output
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -39,8 +41,12 @@ async def enrich_single_item(item_id: str, logger=None) -> bool:
|
|||||||
else:
|
else:
|
||||||
print(f"[@DEBUG] Starting enrichment for item {item_id}")
|
print(f"[@DEBUG] Starting enrichment for item {item_id}")
|
||||||
|
|
||||||
# Get item details from Square
|
# Get item details from Square (only if not already provided)
|
||||||
|
if item_data is None:
|
||||||
item = await asquare.get_item_by_id(item_id)
|
item = await asquare.get_item_by_id(item_id)
|
||||||
|
else:
|
||||||
|
item = item_data
|
||||||
|
|
||||||
item_name = item.get("name", "")
|
item_name = item.get("name", "")
|
||||||
|
|
||||||
if logger:
|
if logger:
|
||||||
|
|||||||
+8
-4
@@ -263,8 +263,10 @@ async def process_webhook(
|
|||||||
print(
|
print(
|
||||||
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
||||||
)
|
)
|
||||||
# Trigger enrichment in background
|
# Trigger enrichment in background with item data to avoid redundant lookup
|
||||||
asyncio.create_task(glue.enrich_single_item(item_id))
|
asyncio.create_task(
|
||||||
|
glue.enrich_single_item(item_id, item_data=item)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
||||||
|
|
||||||
@@ -299,8 +301,10 @@ async def process_webhook(
|
|||||||
print(
|
print(
|
||||||
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
||||||
)
|
)
|
||||||
# Trigger enrichment in background
|
# Trigger enrichment in background with item data to avoid redundant lookup
|
||||||
asyncio.create_task(glue.enrich_single_item(item_id))
|
asyncio.create_task(
|
||||||
|
glue.enrich_single_item(item_id, item_data=item)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user