run_all.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. echo "Starting run at $(date -u +"%Y-%m-%d %H:%M:%S")"
  4. echo "Running schema migrations…"
  5. ruby /app/lib/migrate.rb
  6. ONLY_LIST="${ONLY:-}" # e.g. "meandervalley" or "kentish,break_oday"
  7. SKIP_LIST="${SKIP:-}" # e.g. "hobartcity,latrobe"
  8. DEBUG_FLAG="${DEBUG:-}" # pass through to scrapers
  9. DRY_FLAG="${DRY_RUN:-}" # pass through to scrapers
  10. shopt -s nullglob
  11. SCRIPTS=(/app/scrapers/*.rb)
  12. should_run() {
  13. local name="$1"
  14. if [[ -n "$ONLY_LIST" ]]; then
  15. IFS=',' read -ra arr <<< "$ONLY_LIST"
  16. local pick
  17. for pick in "${arr[@]}"; do
  18. pick="${pick// /}"
  19. if [[ "$name" == "$pick" ]]; then
  20. echo "1"
  21. return
  22. fi
  23. done
  24. echo "0"
  25. return
  26. fi
  27. if [[ -n "$SKIP_LIST" ]]; then
  28. IFS=',' read -ra arr <<< "$SKIP_LIST"
  29. local skip
  30. for skip in "${arr[@]}"; do
  31. skip="${skip// /}"
  32. if [[ "$name" == "$skip" ]]; then
  33. echo "0"
  34. return
  35. fi
  36. done
  37. fi
  38. echo "1"
  39. }
  40. count=0
  41. for f in "${SCRIPTS[@]}"; do
  42. name="$(basename "$f" .rb)"
  43. table="da_${name}"
  44. if [[ "$(should_run "$name")" != "1" ]]; then
  45. continue
  46. fi
  47. echo "Running ${name} -> table ${table}"
  48. TABLE_NAME="$table" DEBUG="$DEBUG_FLAG" DRY_RUN="$DRY_FLAG" ruby "$f" || echo "Error in $f"
  49. count=$((count+1))
  50. done
  51. echo "Finished run at $(date -u +"%Y-%m-%d %H:%M:%S"). Ran ${count} scraper(s)."