← back to Filemaker Mcp
scripts/push-dashboard-revenue.sh
22 lines
#!/bin/zsh
# Refresh the ads-dashboard FMPro revenue number: compute on Mac2 (where FileMaker
# is reachable) then push the aggregate-only JSON to the Kamatera box.
# Wired to run on a schedule via launchd (see pending-approval draft) — until that's
# approved, run manually: zsh scripts/push-dashboard-revenue.sh
set -e
cd "$(dirname "$0")/.."
# Boot race (TK-12257): launchd RunAtLoad fires at login before the network is up,
# so Claris Cognito auth dies with "Network error" -> exit=1. Wait up to ~3 min for
# the Cognito endpoint to answer (any HTTP code = reachable) before computing.
for i in {1..18}; do
code=$(curl -s -o /dev/null -m 5 -w '%{http_code}' https://cognito-idp.us-west-2.amazonaws.com/ || true)
[[ "$code" != "000" ]] && break
echo "$(date -u +%FT%TZ) network not ready (attempt $i/18), waiting 10s" >&2
sleep 10
done
node scripts/dashboard-revenue.mjs
# keep the LOCAL committed copy fresh too, so local :9770 and git don't drift from prod
cp /tmp/fmpro-revenue.json "$HOME/Projects/ads-dashboard/data/fmpro.json" 2>/dev/null || true
scp -q /tmp/fmpro-revenue.json root@45.61.58.125:/root/Projects/ads-dashboard/data/fmpro.json
echo "$(date -u +%FT%TZ) pushed fmpro.json to Kamatera + refreshed local copy"