diff --git a/manifests/core/worker-script.yaml b/manifests/core/worker-script.yaml index 4f1cc73..5dc4af8 100644 --- a/manifests/core/worker-script.yaml +++ b/manifests/core/worker-script.yaml @@ -48,6 +48,20 @@ data: # waiting on a slow-but-legitimate response, causing a duplicate forward. ACK_WAIT_SECONDS = int(os.getenv("ACK_WAIT_SECONDS", "60")) + # Fiesta is a *separate application* (separate repo, separate binary, + # separate business line - jupiter and Fiesta only happen to share one + # Postgres instance). Its tenants' orders need Fiesta's own CreateOrderv3 + # (item validation, atomic order numbers, stock-insufficient checks) - + # jupiter has no equivalent logic and was never meant to process this + # tenant population. jupiter and Fiesta share one `tenants` table with + # no single clean column to tell them apart, so this is an explicit + # allowlist rather than a heuristic. Expand FIESTA_TENANT_IDS as more + # Fiesta tenants are identified (2026-07-29). + FIESTA_BASE_URL = os.getenv("FIESTA_BASE_URL", "http://fiesta.nearle") + FIESTA_TENANT_IDS = set( + int(t) for t in os.getenv("FIESTA_TENANT_IDS", "").split(",") if t.strip() + ) + # Endpoint mapping is still useful for constructing the target URL ENDPOINT_MAPPING = { "/live/api/v1/deliveries/createdeliveries": f"{BASE_URL}/live/api/v1/deliveries/createdeliveries", @@ -56,13 +70,13 @@ data: "/live/api/v2/deliveries/createdeliverylog": f"{BASE_URL}/live/api/v2/deliveries/createdeliverylog", "/live/api/v2/partners/createbreaklog": f"{BASE_URL}/live/api/v2/partners/createbreaklog", "/live/api/v2/partners/updatebreaklog": f"{BASE_URL}/live/api/v2/partners/updatebreaklog", - # v1 CreateOrder only ever writes the order header - it never loops - # over "items", so orderdetails/productstocks are never touched. - # CreateOrderv3 does ("for _, item := range data.Items"), and the - # loop is a no-op when Items is empty, so tenants who never send - # items (their whole order history is header-only, e.g. 916/908) - # behave identically. Tenants who do send items now get them - # persisted instead of silently dropped (2026-07-29). + # Default target for non-Fiesta tenants (jupiter). v1 CreateOrder + # only ever writes the order header - it never loops over "items". + # CreateOrderv3 does, and the loop is a no-op when Items is empty, + # so jupiter-native tenants who never send items (e.g. 916/908) + # behave identically either way. Fiesta tenants are redirected to + # their own backend below, in forward_to_external - this mapping + # is only the fallback for everyone else. "/live/api/v1/mob/orders/createorder": f"{BASE_URL}/live/api/v3/orders/createorder", "/live/api/v1/web/products/create": f"{BASE_URL}/live/api/v1/products/create", "/live/api/v1/mob/customers/login": f"{BASE_URL}/live/api/v1/customers/login", @@ -105,6 +119,27 @@ data: return "DROP", None data_to_forward = payload["data"] + # Fiesta-tenant orders go to Fiesta's own backend instead of jupiter + # - see FIESTA_TENANT_IDS above. tenantid may arrive nested under + # "orders" (mobile app shape) or flat (direct/API-tool shape); this + # is only used to pick the target, Fiesta's own handler does its own + # (more thorough) parsing of the actual body. + if endpoint == "/live/api/v1/mob/orders/createorder" and FIESTA_TENANT_IDS: + tenantid = None + if isinstance(data_to_forward, dict): + orders_obj = data_to_forward.get("orders") + if isinstance(orders_obj, dict) and "tenantid" in orders_obj: + tenantid = orders_obj.get("tenantid") + elif "tenantid" in data_to_forward: + tenantid = data_to_forward.get("tenantid") + try: + tenantid = int(tenantid) if tenantid is not None else None + except (TypeError, ValueError): + tenantid = None + if tenantid in FIESTA_TENANT_IDS: + external_url = f"{FIESTA_BASE_URL}{endpoint}" + print(f"?? Routing tenant {tenantid} createorder to Fiesta backend") + # Payload Normalization for logs if endpoint == "/live/api/v2/deliveries/createdeliverylog": if isinstance(data_to_forward, dict): diff --git a/manifests/core/workers.yaml b/manifests/core/workers.yaml index cd33d74..c6c2c6b 100644 --- a/manifests/core/workers.yaml +++ b/manifests/core/workers.yaml @@ -98,6 +98,14 @@ spec: optional: true - name: EXTERNAL_BASE_URL value: "http://jupiter.nearle" + - name: FIESTA_BASE_URL + value: "http://fiesta.nearle" + # Known Fiesta tenants (R mart=1147, Suriya Store=1135, confirmed + # 2026-07-29). Expand as more are identified - see worker.py's + # FIESTA_TENANT_IDS comment for why this is an explicit list rather + # than a DB heuristic. + - name: FIESTA_TENANT_IDS + value: "1147,1135" resources: requests: memory: "128Mi"