← back to Fentucci Naturals

scripts/resume.sh

31 lines

#!/usr/bin/env bash
# Fentucci Naturals (Tokiwa) go-live — daily TRICKLE driver (idempotent, self-unloading).
# Steve override 2026-07-26: activate quote-only ($0 per-yard dropped, $4.25 sample kept).
# All 504 drafts already exist + settlement is clean, so a tick is just the go-live
# trickle. Activates up to GOLIVE_LIMIT/day (shared 'backlog' cadence; NO bulk-dump).
# Self-unloads its launchd job once every draft is live-or-held.
set -uo pipefail
ROOT="$HOME/Projects/fentucci-naturals"
cd "$ROOT" || exit 1
export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@14/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
LOG="$ROOT/logs/go-live-resume.log"; mkdir -p "$ROOT/logs"
GOLIVE_LIMIT="${DW_FENTUCCI_GOLIVE_LIMIT:-40}"   # activations per day (backlog cadence)
LABEL="com.steve.fentucci-onboard-resume"
# grep-export (never `source` — an unquoted value in the secrets .env aborts set -a)
SHOPIFY_ADMIN_TOKEN=$(grep '^SHOPIFY_ADMIN_TOKEN=' "$HOME/Projects/secrets-manager/.env" | cut -d= -f2- | tr -d '"')
export SHOPIFY_ADMIN_TOKEN
ts() { date '+%Y-%m-%dT%H:%M:%S'; }
{
  echo "===== $(ts) fentucci go-live tick (limit ${GOLIVE_LIMIT}) ====="
  python3 scripts/go-live.py --apply --limit="${GOLIVE_LIMIT}"
  TOTAL=$(wc -l < data/created.jsonl | tr -d ' ')
  GOLIVE=$([ -f data/golive-done.jsonl ] && wc -l < data/golive-done.jsonl | tr -d ' ' || echo 0)
  HELD=$([ -f data/golive-held.jsonl ] && sort -u data/golive-held.jsonl | wc -l | tr -d ' ' || echo 0)
  echo "$(ts) state: total=${TOTAL} golive=${GOLIVE} held=${HELD}"
  if [ "$((GOLIVE + HELD))" -ge "${TOTAL}" ]; then
    echo "$(ts) ✅ all ${TOTAL} Fentucci drafts live-or-held — unloading ${LABEL}"
    launchctl bootout "gui/$(id -u)/${LABEL}" 2>/dev/null || launchctl unload "$HOME/Library/LaunchAgents/${LABEL}.plist" 2>/dev/null
  fi
  echo "===== $(ts) tick done ====="
} >> "$LOG" 2>&1