diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 4a279be..8e70623 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -9,6 +9,17 @@ APP_DIR="${APP_DIR:-/opt/thermograph}" BRANCH="${BRANCH:-main}" cd "$APP_DIR" +# Pre-warm the ~750 city-page archives so /climate pages serve from cache and a +# search-engine crawl never bursts the archive API quota. Detached + backgrounded +# so it never blocks the deploy or health check; idempotent (skips already-cached +# cells), so it's cheap on every deploy after the first full warm. +warm_city_archives() { + mkdir -p "$APP_DIR/logs" + echo "==> Warming city-page archives in the background (logs/warm-cities.log)" + setsid nohup bash -c "cd '$APP_DIR/backend' && exec '$APP_DIR/.venv/bin/python' warm_cities.py --pace 2" \ + "$APP_DIR/logs/warm-cities.log" 2>&1 & +} + echo "==> Fetching $BRANCH" git fetch --prune origin "$BRANCH" git reset --hard "origin/$BRANCH" @@ -31,6 +42,7 @@ url="http://127.0.0.1:${PORT}${BASE%/}/" for i in $(seq 1 15); do if curl -fsS -o /dev/null "$url"; then echo "==> OK: $url is serving" + warm_city_archives exit 0 fi sleep 1