cleanup_remote_runtime.sh 994 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # API base URL
  3. BASE_URL="https://runtime.eval.all-hands.dev"
  4. # Get the list of runtimes
  5. response=$(curl --silent --location --request GET "${BASE_URL}/list" \
  6. --header "X-API-Key: ${ALLHANDS_API_KEY}")
  7. n_runtimes=$(echo $response | jq -r '.total')
  8. echo "Found ${n_runtimes} runtimes. Stopping them..."
  9. runtime_ids=$(echo $response | jq -r '.runtimes | .[].runtime_id')
  10. # Function to stop a single runtime
  11. stop_runtime() {
  12. local runtime_id=$1
  13. local counter=$2
  14. echo "Stopping runtime ${counter}/${n_runtimes}: ${runtime_id}"
  15. curl --silent --location --request POST "${BASE_URL}/stop" \
  16. --header "X-API-Key: ${ALLHANDS_API_KEY}" \
  17. --header "Content-Type: application/json" \
  18. --data-raw "{\"runtime_id\": \"${runtime_id}\"}"
  19. echo
  20. }
  21. export -f stop_runtime
  22. export BASE_URL ALLHANDS_API_KEY n_runtimes
  23. # Use GNU Parallel to stop runtimes in parallel
  24. echo "$runtime_ids" | parallel -j 16 --progress stop_runtime {} {#}
  25. echo "All runtimes have been stopped."