← back to Pj Image Repair
run_tranches.sh
50 lines
#!/usr/bin/env bash
# TK-10467 — bounded tranche driver for the Steve-approved (2026-09-23) full-pool PJ hero write.
# Tier-1 rows 26..2303 in tranches of <=460, then Tier-2 (32). After every tranche: sample 10
# public-storefront PDPs (anonymous, not Admin API) and STOP on any error or any sample failure.
# Requires CONFIRM_PJ_WRITE=1 and the lock at /tmp/pj-canary-TK10467.lock held by the caller.
set -uo pipefail
cd "$(dirname "$0")"
LOG=data/tranche_run_$(date -u +%Y%m%dT%H%M%SZ).log
: "${CONFIRM_PJ_WRITE:?set CONFIRM_PJ_WRITE=1}"
[ -f /tmp/pj-canary-TK10467.lock ] || { echo "no lock — refusing"; exit 2; }
sample_public() { # $1=map $2=offset $3=count -> exit 1 on any non-real pos1
python3 - "$1" "$2" "$3" <<'EOF'
import csv, json, sys, urllib.request, random
m, off, n = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
rows = list(csv.DictReader(open(m), delimiter="\t"))[off:off+n]
random.seed(off); pick = random.sample(rows, min(10, len(rows)))
bad = 0
for r in pick:
tok = r["real_image"].split("?")[0].rsplit("/",1)[-1].rsplit(".",1)[0]
try:
d = json.load(urllib.request.urlopen(f"https://designerwallcoverings.com/products/{r['handle']}.json", timeout=30))
src = d["product"]["images"][0]["src"]
ok = tok in src and "Logo" not in src
except Exception as e:
ok = False; src = f"ERR {e}"
print((" ok " if ok else " BAD ") + r["dw_sku"] + " " + src.rsplit("/",1)[-1][:60])
bad += (not ok)
print(f"sample: {len(pick)-bad}/{len(pick)} real@pos1")
sys.exit(1 if bad else 0)
EOF
}
run_tranche() { # $1=map $2=offset $3=limit $4=label
echo "=== $4: map=$1 offset=$2 limit=$3 $(date -u +%FT%TZ) ===" | tee -a "$LOG"
PJ_MAP="$1" python3 write_shopify_images.py --apply --offset="$2" --limit="$3" 2>&1 | tee -a "$LOG" | grep -E "^(\[[0-9]+\] (ERR|WARN|HTTP|STOP)|done )"
local summary; summary=$(tail -1 "$LOG")
echo "$summary" | grep -q " err=0 " || { echo "!!! $4 had errors — HALTING: $summary" | tee -a "$LOG"; exit 1; }
echo "--- public sample after $4 ---" | tee -a "$LOG"
sample_public "$1" "$2" "$3" 2>&1 | tee -a "$LOG" || { echo "!!! $4 public sample FAILED — HALTING" | tee -a "$LOG"; exit 1; }
}
run_tranche data/pj_writable.tsv 26 460 "T1-a"
run_tranche data/pj_writable.tsv 486 460 "T1-b"
run_tranche data/pj_writable.tsv 946 460 "T1-c"
run_tranche data/pj_writable.tsv 1406 460 "T1-d"
run_tranche data/pj_writable.tsv 1866 438 "T1-e"
run_tranche data/pj_tier2_writable.tsv 0 32 "T2"
echo "=== ALL TRANCHES COMPLETE $(date -u +%FT%TZ) ===" | tee -a "$LOG"