test glue
This commit is contained in:
1 parent
03f6e84965
commit
d341684567
3 files changed
+413
-40
No files matched your search
+68
-3
@@ -12,6 +12,8 @@ from square.utils.webhooks_helper import verify_signature
|
||||
# Configuration
|
||||
SQUARE_WEBHOOK_SIGNATURE_KEY = sq_env.SQUARE_WEBHOOK_SIGNATURE_KEY
|
||||
SQUARE_WEBHOOK_URL = sq_env.SQUARE_WEBHOOK_URL
|
||||
SQUARE_LEGO_CAT_ID = sq_env.LEGO_CAT_ID
|
||||
|
||||
|
||||
# Debug: Print configuration (redact key)
|
||||
if SQUARE_WEBHOOK_SIGNATURE_KEY:
|
||||
@@ -233,17 +235,77 @@ async def process_webhook(
|
||||
inventory_counts = (
|
||||
data.get("data", {}).get("object", {}).get("inventory_counts", [])
|
||||
)
|
||||
|
||||
# Import here to avoid circular imports
|
||||
from src import asquare, glue
|
||||
|
||||
for count in inventory_counts:
|
||||
catalog_id = count.get("catalog_object_id")
|
||||
variation_id = count.get("catalog_object_id")
|
||||
quantity = count.get("quantity")
|
||||
state = count.get("state")
|
||||
print(
|
||||
f"[PROCESS] Catalog: {catalog_id}, Qty: {quantity}, State: {state}"
|
||||
f"[PROCESS] Catalog: {variation_id}, Qty: {quantity}, State: {state}"
|
||||
)
|
||||
|
||||
try:
|
||||
# Get parent item from variation ID
|
||||
item = await asquare.get_item_by_variation_id(variation_id)
|
||||
item_id = item.get("id")
|
||||
item_name = item.get("name", "")
|
||||
category_id = item.get("category_id")
|
||||
|
||||
print(f"[PROCESS] Item: {item_id} - {item_name}")
|
||||
print(f"[PROCESS] Category: {category_id}")
|
||||
|
||||
# Only process LEGO category items
|
||||
if category_id == SQUARE_LEGO_CAT_ID:
|
||||
print(
|
||||
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
||||
)
|
||||
# Trigger enrichment in background
|
||||
asyncio.create_task(glue.enrich_single_item(item_id))
|
||||
else:
|
||||
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to process variation {variation_id}: {e}")
|
||||
|
||||
elif webhook_type == "catalog.version.updated":
|
||||
print(f"[PROCESS] Processing catalog version update...")
|
||||
# Add your catalog processing logic here
|
||||
|
||||
# Import here to avoid circular imports
|
||||
from src import asquare, glue
|
||||
|
||||
catalog_object = data.get("data", {}).get("object", {})
|
||||
object_type = catalog_object.get("type")
|
||||
|
||||
if object_type == "ITEM":
|
||||
item_id = catalog_object.get("id")
|
||||
print(f"[PROCESS] Item updated: {item_id}")
|
||||
|
||||
try:
|
||||
# Get item details to check category
|
||||
item = await asquare.get_item_by_id(item_id)
|
||||
item_name = item.get("name", "")
|
||||
category_id = item.get("category_id")
|
||||
|
||||
print(f"[PROCESS] Item: {item_id} - {item_name}")
|
||||
print(f"[PROCESS] Category: {category_id}")
|
||||
|
||||
# Only process LEGO category items
|
||||
if category_id == SQUARE_LEGO_CAT_ID:
|
||||
print(
|
||||
f"[PROCESS] ✓ LEGO item detected - triggering enrichment"
|
||||
)
|
||||
# Trigger enrichment in background
|
||||
asyncio.create_task(glue.enrich_single_item(item_id))
|
||||
else:
|
||||
print(f"[PROCESS] ✗ Not a LEGO item - skipping enrichment")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to process item {item_id}: {e}")
|
||||
else:
|
||||
print(f"[PROCESS] Object type '{object_type}' - skipping")
|
||||
|
||||
else:
|
||||
print(f"[PROCESS] Webhook type '{webhook_type}' - no handler configured")
|
||||
@@ -252,6 +314,9 @@ async def process_webhook(
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to process webhook {event_id}: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user