← back to Homesonspec
auto-save: 2026-08-05T14:42:56 (1 files) — ops/drain-dr-horton-night.sh
b7da7ff9781e12c69b1cd8db0d740778856a2f10 · 2026-08-05 14:43:04 -0700 · Steve Abrams
Files touched
A ops/drain-dr-horton-night.sh
Diff
commit b7da7ff9781e12c69b1cd8db0d740778856a2f10
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Wed Aug 5 14:43:04 2026 -0700
auto-save: 2026-08-05T14:42:56 (1 files) — ops/drain-dr-horton-night.sh
---
ops/drain-dr-horton-night.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/ops/drain-dr-horton-night.sh b/ops/drain-dr-horton-night.sh
new file mode 100644
index 00000000..2720f686
--- /dev/null
+++ b/ops/drain-dr-horton-night.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# drain-dr-horton-night.sh — Steve-approved 2026-08-05: reactivate D.R. Horton + drain its states to
+# find more spec homes. ONE-TIME backfill, run once in the MIDDLE OF THE NIGHT (after the 04:30
+# crawl-cache prune = max disk headroom, off-peak). After this run dr-horton-site stays ACTIVE and the
+# normal ingest worker maintains it — so schedule this ONCE (a one-shot `at`/one-time cron), NOT a
+# permanent nightly cron. DR Horton auto-paused during a transient disk-full at 03:31; the adapter is
+# healthy, the source just needs reactivation. Disk-aware so it can never re-fill the disk and
+# re-crash prod PG (the failure mode that paused it). $0 — plain-fetch scrape.
+set -uo pipefail
+cd /root/Projects/homesonspec || exit 1
+mkdir -p /root/logs
+LOG=/root/logs/drain-dr-horton.log
+DBURL=$(grep -hoE 'postgresql://[^ "]+' .env | head -1)
+MIN_FREE_GB="${MIN_FREE_GB:-40}" # hard stop: never drain below this much free disk
+PRUNE_BELOW_GB="${PRUNE_BELOW_GB:-90}" # run the cache prune first if free is below this
+# DR Horton's larger states first; edit/extend as needed.
+STATES="${DRHORTON_STATES:-texas florida georgia north-carolina south-carolina arizona california colorado tennessee nevada alabama}"
+
+say(){ echo "$(date -u +%FT%TZ) $*" | tee -a "$LOG"; }
+free_gb(){ df -BG --output=avail / | tail -1 | tr -dc '0-9'; }
+homes(){ psql "$DBURL" -tAc 'SELECT count(*) FROM "InventoryHome" WHERE "isDemo"=false' 2>/dev/null; }
+
+say "=== DR Horton night drain START (free $(free_gb)G) ==="
+
+# 0) ensure disk headroom before writing anything
+if [ "$(free_gb)" -lt "$PRUNE_BELOW_GB" ]; then
+ say "free $(free_gb)G < ${PRUNE_BELOW_GB}G — pruning crawl cache first"
+ [ -x ops/prune-snapshot-cache.sh ] && ops/prune-snapshot-cache.sh --apply >> "$LOG" 2>&1
+ say "post-prune free $(free_gb)G"
+fi
+if [ "$(free_gb)" -lt "$MIN_FREE_GB" ]; then
+ say "ABORT — only $(free_gb)G free (< ${MIN_FREE_GB}G) even after prune. Not draining. Investigate disk."
+ exit 1
+fi
+
+# 1) reactivate the source (clears the auto-pause + benign failure counter)
+psql "$DBURL" -c "UPDATE \"SourceRegistry\" SET active=true, \"consecutiveFailures\"=0, health='HEALTHY' WHERE key='dr-horton-site';" >> "$LOG" 2>&1 \
+ && say "reactivated dr-horton-site" || { say "reactivate failed — aborting"; exit 1; }
+
+# 2) staged per-state drain with a disk guard after every state
+BEFORE=$(homes)
+for ST in $STATES; do
+ FG=$(free_gb)
+ if [ "$FG" -lt "$MIN_FREE_GB" ]; then say "STOP — free ${FG}G < ${MIN_FREE_GB}G; halting before $ST (resume tomorrow night)"; break; fi
+ say "draining $ST (free ${FG}G)…"
+ DRHORTON_STATE="$ST" pnpm --filter @homesonspec/workers pipeline -- --adapter=dr-horton-site >> "$LOG" 2>&1 \
+ || say " $ST run reported an error (continuing to next state)"
+done
+
+AFTER=$(homes)
+say "=== DONE. homes ${BEFORE} -> ${AFTER} (+$((AFTER-BEFORE))). free $(free_gb)G ==="
← 033d4dbb workers: exp_backoff_restart_delay to cap PG-outage restart
·
back to Homesonspec
·
auto-save: 2026-08-05T15:43:31 (1 files) — ops/drain-dr-hort af17a415 →