← back to Dw Photo Capture

visual-search/embed-nightly-mac2.sh

30 lines

#!/bin/bash
# Mac2 nightly embed top-up — keeps CLIP coverage of the ACTIVE catalog from decaying
# as new products land. Runs both embedders resumably (each skips already-done rows),
# then hot-reloads the search index. Safe to run any time; $0 local.
# launchd: com.steve.visual-search-embed-nightly (see plist next to this script).
set -u
export PATH="/opt/homebrew/bin:/opt/homebrew/opt/postgresql@14/bin:/usr/local/bin:$PATH"   # launchd PATH lacks psql
cd "$(dirname "$0")" || exit 1
# DB user: env-first. The old hard-coded `stevestudio2` role is retired; the repo's known-good
# convention (server.js DW_DB default + .env.example) is local peer auth as the RUNNING OS user,
# so default to PGUSER, else `id -un` (macstudio3 under launchd). TK-12090 Lane P.
export DW_UNIFIED_DB="${DW_UNIFIED_DB:-postgresql://${PGUSER:-$(id -un)}@/dw_unified?host=/tmp}"
# Fail loud (and early) if the conninfo can't connect, instead of two embedders erroring silently.
if ! psql "$DW_UNIFIED_DB" -tAc "select 1" >/dev/null 2>&1; then
  echo "$(date -u +%FT%TZ) nightly: ABORT — cannot connect with DW_UNIFIED_DB user=${PGUSER:-$(id -un)}" >> embed-nightly.log
  exit 2
fi
PY=./.venv-similar/bin/python
LOG=embed-nightly.log

echo "$(date -u +%FT%TZ) nightly: start" >> "$LOG"
# 1) vendor_catalog stragglers (existing embedder, resumable)
nice -n 15 "$PY" embed_catalog.py --workers 16 --limit 20000 >> "$LOG" 2>&1
# 2) shopify-only actives (gap embedder, resumable via negative-key placeholders)
nice -n 15 "$PY" embed_shopify_gap.py --workers 16 >> "$LOG" 2>&1
# 3) refresh the in-RAM index so new vectors are searchable
curl -s --max-time 120 http://127.0.0.1:9914/reload >> "$LOG" 2>&1
echo "" >> "$LOG"
echo "$(date -u +%FT%TZ) nightly: done" >> "$LOG"