[object Object]

← back to Fineartamerica Price Sync

Harden apply (retry/continue); purge invalid $0 costs; all 408 valid FAA variants repriced live

802216f752ac872d0702214fbe80553cca77a272 · 2026-07-16 09:29:29 -0700 · Steve Abrams

Files touched

Diff

commit 802216f752ac872d0702214fbe80553cca77a272
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Jul 16 09:29:29 2026 -0700

    Harden apply (retry/continue); purge invalid $0 costs; all 408 valid FAA variants repriced live
---
 sync.js | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/sync.js b/sync.js
index bca2acb..4d829c8 100644
--- a/sync.js
+++ b/sync.js
@@ -91,12 +91,23 @@ const ROUND = val('--round') || 'cent';
   }
   const toWrite = rows.filter(r => r.status === 'REPRICE');
   console.log(`\nAPPLYING ${toWrite.length} live price writes to the production store…`);
-  let ok = 0;
+  let ok = 0, err = 0;
   for (const r of toWrite) {
-    await updateVariantPrice(r.variantId, r.target.toFixed(2));
-    ok++;
-    console.log(`  ✓ ${r.variant.padEnd(30)} $${r.current.toFixed(2)} → $${r.target.toFixed(2)}`);
-    await new Promise(s => setTimeout(s, 550)); // Shopify 2 req/s courtesy
+    // resilient write: retry on 429/5xx with backoff; never let one bad call
+    // abort the whole batch (a single rate-limit used to leave it partial).
+    let done = false;
+    for (let attempt = 1; attempt <= 5 && !done; attempt++) {
+      try {
+        await updateVariantPrice(r.variantId, r.target.toFixed(2));
+        ok++; done = true;
+        console.log(`  ✓ ${r.variant.padEnd(30)} $${r.current.toFixed(2)} → $${r.target.toFixed(2)}`);
+      } catch (e) {
+        const transient = /\b(429|5\d\d)\b/.test(e.message);
+        if (transient && attempt < 5) { await new Promise(s => setTimeout(s, 1000 * attempt)); }
+        else { err++; done = true; console.log(`  ✗ ${r.variant.padEnd(30)} — ${e.message.slice(0, 80)}`); }
+      }
+    }
+    await new Promise(s => setTimeout(s, 600)); // Shopify ~2 req/s courtesy
   }
-  console.log(`\nDONE: ${ok}/${toWrite.length} variants repriced.`);
+  console.log(`\nDONE: ${ok}/${toWrite.length} repriced${err ? `, ${err} errored` : ''}.`);
 })().catch(e => { console.error(e); process.exit(1); });

← cc49883 auto-save: 2026-07-16T09:12:20 (3 files) — bin/faa-fetch-all  ·  back to Fineartamerica Price Sync  ·  Monthly price-sync job: propose-only drift check + launchd p daaf7c7 →