start_batch_ingest.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. #ident "@(#)$Format:LocalFoodAI_lanfr144:start_batch_ingest.sh:%an:%ae:%ad:%cn:%ce:%cd:%H:%D:%N$"
  3. # Local Food AI - Disconnected Ingestion Wrapper
  4. # This script uses nohup to run the python ingestion script in the background.
  5. # You can exit your SSH session safely after starting this script.
  6. echo "========================================================="
  7. echo "🍔 Local Food AI: Extreme Batch Ingestion"
  8. echo "========================================================="
  9. if [ ! -f "data/en.openfoodfacts.org.products.csv" ] && [ ! -f "data/fr.openfoodfacts.org.products.csv" ]; then
  10. echo "❌ Error: CSV files not found in the data/ directory."
  11. echo "Please download the massive CSVs before running this batch."
  12. exit 1
  13. fi
  14. # Load DB environment variables for ingestion and migrations from .env
  15. if [ -f .env ]; then
  16. DB_LOADER_PASS=$(grep '^DB_LOADER_PASS=' .env | cut -d'=' -f2- | tr -d '\r')
  17. export DB_HOST="127.0.0.1"
  18. export DB_USER="food_loader"
  19. export DB_PASS="$DB_LOADER_PASS"
  20. fi
  21. echo "🚀 Running database migrations to ensure schema health..."
  22. # Run database migrations
  23. venv/bin/python3 -m alembic upgrade head
  24. echo "🚀 Triggering background ingestion process via nohup..."
  25. echo "All outputs will be saved to ingestion_process.log"
  26. # Run securely in background with --wipe flag to clean products database
  27. nohup venv/bin/python3 -u ingest_csv.py --wipe > ingestion_process.log 2>&1 &
  28. BG_PID=$!
  29. echo "✅ Process started in the background (PID: $BG_PID)"
  30. echo "You can now safely close your terminal or turn off your computer."
  31. echo "To monitor progress from the server later, run:"
  32. echo " tail -f ingestion_process.log"