← back to Dw Pitch Followup

scripts/refresh.sh

29 lines

#!/bin/sh
# refresh.sh — rebuild the pitch lists from FileMaker, then pre-triage the whole board.
# Run by launchd (com.steve.dw-pitch-rebuild) 3x/day + on boot. Both steps are $0 (local).
set -e
DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$DIR"
NODE=/opt/homebrew/bin/node
echo "=== refresh $(date) ==="
# Network-readiness guard: RunAtLoad fires this on boot BEFORE the network is up, which
# FATALs build-lists.js on Claris ID (AWS Cognito) auth every reboot. Wait up to ~120s for
# connectivity, then proceed regardless (never hang). (yoloforever cycle 4, Cody-caught.)
n=0
until curl -sS --max-time 4 -o /dev/null https://www.apple.com 2>/dev/null; do
  n=$((n + 1))
  [ "$n" -ge 24 ] && { echo "[refresh] network not up after ~120s — proceeding anyway"; break; }
  sleep 5
done
# Retry build-lists: Claris ID (AWS Cognito) auth intermittently FATALs with "Network error"
# even after the connectivity guard passes (TK-12258, 2026-09-25 11:52 run). Up to 3 tries.
t=1
until "$NODE" scripts/build-lists.js; do
  [ "$t" -ge 3 ] && { echo "[refresh] build-lists failed after $t attempts"; exit 1; }
  echo "[refresh] build-lists attempt $t failed — retrying in 60s"
  t=$((t + 1)); sleep 60
done
# pre-triage hits the running server (owns the follow-up cache); non-fatal if it can't
"$NODE" scripts/pretriage.js || echo "[refresh] pretriage skipped/failed (non-fatal)"
echo "=== refresh done $(date) ==="