← back to New Import Viewer

run-cadence.sh

39 lines

#!/bin/zsh
# CADENCE WRAPPER — one hourly tick of the staggered 1,000-published-SKUs/24h plan.
# Drains exactly ONE batch worth (42) of cadence manifests through consumer.js LIVE,
# creating + publishing 42 PUBLISHED SKUs to the Online Store, then exits.
#
# 42/hr × 24h ≈ 1,008/day. consumer.js dedups by id across manifests + is ledgered,
# so this is idempotent and resumable — a missed hour just means the next tick picks
# up the same oldest unprocessed rows.
#
# GATES (Steve-owned): goes LIVE only when BOTH are present —
#   • env LAUNCH_CONSUMER_LIVE=1   (the Steve ceiling; the plist sets it)
#   • --live + --allow-active      (this script passes them so products PUBLISH)
# Without the env it stays dry-run (safe no-op), so enabling/disabling the cadence
# is a single env flip in the plist.
#
# Daily VARIANT-creation limit: if Shopify returns 429 "Daily variant creation
# limit", consumer.js retries then fails the row; the ledger records it and the
# next hour re-attempts. We do NOT hammer — one 42-row tick per hour.
set -euo pipefail

cd "$(dirname "$0")"
export PATH="/opt/homebrew/bin:/usr/bin:/bin:/usr/local/bin:$PATH"

LIMIT="${CADENCE_LIMIT:-42}"
LOG="data/cadence-$(date +%Y%m%d).log"
TS="$(date -u +%Y-%m-%dT%H:%M:%SZ)"

echo "[$TS] cadence tick start (limit=$LIMIT, live=${LAUNCH_CONSUMER_LIVE:-unset})" >> "$LOG"

# --allow-active makes products ACTIVE; consumer.js then publishablePublish'es each
# to the Online Store (the 2026-06-19 publish-gap fix). Dry by default unless the
# env ceiling is set.
node consumer.js --live --allow-active --limit "$LIMIT" >> "$LOG" 2>&1 || {
  echo "[$TS] cadence tick exited non-zero (likely dry-refusal or 429) — see log" >> "$LOG"
  exit 0   # never crash-loop the launchd job; a bad tick is logged, next hour retries
}

echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] cadence tick done" >> "$LOG"