← back to Abrams

scripts/tick.sh

69 lines

#!/usr/bin/env bash
# tick.sh — YOLO loop body. Fires every 15 minutes via launchd.
# Read-only against the rest of the stack. Never writes to dw_unified, Shopify, or prod data.
set -euo pipefail

cd "$(dirname "$0")/.."
LOG="data/build-log.jsonl"
STAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)"

emit() {
  local type="$1"; shift
  local payload="$1"; shift || true
  echo "{\"ts\":\"$STAMP\",\"type\":\"$type\",$payload}" >> "$LOG"
}

emit "tick-start" "\"tick\":\"$(date +%s)\""

# 1) re-inventory projects (read-only)
if node scripts/inventory.js 2>>data/err.log; then
  emit "inventory-ok" "\"phase\":\"inventory\""
else
  emit "inventory-err" "\"phase\":\"inventory\""
fi

# 2) generate 1 new SWOT
if node scripts/swot-gen.js 2>>data/err.log; then
  emit "swot-ok" "\"phase\":\"swot\""
else
  emit "swot-err" "\"phase\":\"swot\""
fi

# 3) git auto-commit if anything changed in data/
if [ -d .git ]; then
  if [ -n "$(git status --porcelain data/ 2>/dev/null || true)" ]; then
    git add data/ >/dev/null 2>&1 || true
    git -c user.email=steve@designerwallcoverings.com -c user.name="Abrams Panel" commit -q -m "tick: refresh inventory + SWOT at $STAMP" 2>>data/err.log || true
    emit "git-commit" "\"phase\":\"git\""
  fi
fi

# 3.5) refresh cross-project counters
if node scripts/counters.js 2>>data/err.log; then
  emit "counters-ok" "\"phase\":\"counters\""
fi

# 3.6) refresh market data (Yahoo)
if node scripts/market-data.js 2>>data/err.log; then
  emit "market-ok" "\"phase\":\"market\""
fi

# 3.7) refresh Abrams proprietary indexes
if node scripts/abrams-indexes.js 2>>data/err.log; then
  emit "abrams-idx-ok" "\"phase\":\"abrams-indexes\""
fi

# 4) re-audit Mag-20
if node scripts/mag-20-audit.js 2>>data/err.log; then
  emit "mag-20-ok" "\"phase\":\"audit\""
else
  emit "mag-20-err" "\"phase\":\"audit\""
fi

# 5) drain any queued emails through George (if available)
if [ -x scripts/drain-queue.sh ]; then
  bash scripts/drain-queue.sh 2>>data/err.log || true
fi

emit "tick-done" "\"tick\":\"$(date +%s)\""