← back to Nationalrealestate
scripts/refresh-commercial.sh
35 lines
#!/usr/bin/env bash
# Daily refresh for the LA commercial-RE-news data. Safe on prod (Kamatera) OR local.
# - CA DRE broker/firm registry: the source (secure.dre.ca.gov) refreshes DAILY,
# so re-pull keeps LA firm/broker intel current. Self-contained (fetches the file).
# - LA commercial parcels: re-materialize from the assessor sqlite (changes rarely,
# but cheap + idempotent — the ETL DELETEs+reloads county 06037).
# - Briefs: local-LLM only, so run ONLY where an Ollama is reachable (skipped on prod).
#
# Install as a daily cron (gated — see the pending-approval memo). Logs to /tmp.
set -uo pipefail
cd "$(dirname "$0")/.." || exit 1
LOG=/tmp/refresh-commercial.log
echo "=== $(date) refresh-commercial start ===" >> "$LOG"
NODE_OPTIONS=--max-old-space-size=6144 npm run ingest:brokers -- ca >> "$LOG" 2>&1 \
&& echo "[ok] ca_dre registry refreshed" >> "$LOG" \
|| echo "[FAIL] ca_dre registry" >> "$LOG"
npm run ingest:commercial -- la >> "$LOG" 2>&1 \
&& echo "[ok] la commercial parcels refreshed" >> "$LOG" \
|| echo "[skip/FAIL] la commercial (sqlite may be absent on this host)" >> "$LOG"
# Briefs need a real local LLM. Auto-detecting :11434 is unreliable (prod answers /api/tags
# but has no usable model, and the script's bash default can differ from briefs.ts's
# dotenv OLLAMA_URL). So gate on an EXPLICIT opt-in: only run where REFRESH_BRIEFS=1 is set
# (i.e. on Mac2). The prod cron never sets it -> briefs are always skipped there.
if [ "${REFRESH_BRIEFS:-0}" = "1" ]; then
npm run ingest:commercial-briefs >> "$LOG" 2>&1 \
&& echo "[ok] briefs regenerated (Ollama present)" >> "$LOG" \
|| echo "[FAIL] briefs" >> "$LOG"
else
echo "[skip] briefs — no Ollama reachable on this host" >> "$LOG"
fi
echo "=== $(date) refresh-commercial done ===" >> "$LOG"