← back to Rebel Walls Push
scripts/cadence-daily-step.sh
58 lines
#!/usr/bin/env bash
# cadence-daily-step.sh — Rebel Walls' slice of the DW daily cadence.
# Pushes a SMALL daily batch of net-new Rebel Walls MURALS (every RW SKU is a mural, priced per m²)
# to Shopify, budget-COORDINATED with the shared variant-cap ledger so it never races the hourly
# uploader / Osborne / Anna French (the collision that caused the old bulk job's throttle errors).
#
# Steve 2026-06-30: "5 new SKUs a day, focusing on murals." Replaces the disabled bulk
# com.steve.rebel-walls-daily-push (which pushed ~550/day uncoordinated).
#
# DRY-RUN BY DEFAULT — prints what it WOULD push and makes NO Shopify writes.
# Pass --commit (or LIVE=1) to actually create products. SENDING live is Steve-gated.
#
# bash scripts/cadence-daily-step.sh # dry-run, 5 murals
# RW_DAILY=5 bash scripts/cadence-daily-step.sh --commit # LIVE create 5
set -u
export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin"
# DB password is env-first (secret-strip rule 2026-05-30) — source it from the canonical secrets .env.
SECRETS="$HOME/Projects/secrets-manager/.env"
[ -f "$SECRETS" ] && [ -z "${DW_ADMIN_DB_PASSWORD:-}" ] && \
export DW_ADMIN_DB_PASSWORD="$(grep -E '^DW_ADMIN_DB_PASSWORD=' "$SECRETS" | head -1 | cut -d= -f2- | tr -d "\"'")"
DIR="$HOME/Projects/rebel-walls-push"
BUDGET="$HOME/Projects/designerwallcoverings/scripts/variant-budget/budget.cjs"
N="${RW_DAILY:-5}" # target murals/day
COMMIT=""; [ "${1:-}" = "--commit" ] && COMMIT=1; [ "${LIVE:-}" = "1" ] && COMMIT=1
LOG="$DIR/data/cadence-daily-$(date +%Y%m%d-%H%M%S).log"
LOCK="/tmp/rw-cadence-daily.lock"
cd "$DIR" || exit 1
mkdir -p data
if ! mkdir "$LOCK" 2>/dev/null; then echo "$(date '+%F %T') still running — skip" | tee -a "$LOG"; exit 0; fi
trap 'rmdir "$LOCK" 2>/dev/null' EXIT
echo "$(date '+%F %T') ===== RW cadence daily step (target=$N, commit=${COMMIT:-0}) =====" | tee -a "$LOG"
# Coordinate with the shared ~1,000/day variant cap. budget.cjs fails OPEN (grants the request) if the
# ledger is unreachable, so this never blocks; on a saturated day it hands back fewer than N.
# IMPORTANT: `take` MUTATES the ledger (reserves cap) — only call it on a real (--commit) run, never dry.
GRANT="$N"
if [ -n "$COMMIT" ] && [ -f "$BUDGET" ]; then
GRANT=$(node "$BUDGET" take rebel "$N" 2>/dev/null || echo "$N")
echo "budget grant: $GRANT (requested $N)" | tee -a "$LOG"
else
echo "dry-run: skipping budget reserve; would request $N" | tee -a "$LOG"
fi
[ -z "$GRANT" ] && GRANT="$N"
if [ "$GRANT" -lt 1 ] 2>/dev/null; then echo "no budget this slot — exit clean" | tee -a "$LOG"; exit 0; fi
# push.js pulls the next $GRANT unpushed, non-dedup_skip rows ORDER BY id (all are murals).
if [ -n "$COMMIT" ]; then
node scripts/push.js --all --limit "$GRANT" 2>&1 | tee -a "$LOG"
else
# push.js dry flag is --dry-run (NOT --dry). Getting this wrong creates LIVE products.
node scripts/push.js --all --limit "$GRANT" --dry-run 2>&1 | tee -a "$LOG"
fi
REMAIN=$(psql -d dw_unified -tAc "SELECT count(*) FROM rebelwalls_catalog WHERE (shopify_product_id IS NULL OR shopify_product_id='') AND dedup_skip IS NOT TRUE;" 2>/dev/null | tr -d ' ')
echo "$(date '+%F %T') done — net-new RW murals remaining: ${REMAIN:-?}" | tee -a "$LOG"