in_parallel.sh 748 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. set -e
  3. if [ $# -lt 2 ]; then
  4. echo "Usage: $0 <cmd> [args...]"
  5. echo " Will run cmd arg1, cmd arg2 etc on different circle shared,"
  6. echo " based on what the scheduler says."
  7. exit 2
  8. fi
  9. if [ -z "$CIRCLECI" ]; then
  10. echo "I'm afraid this only works when run on CircleCI"
  11. exit 1
  12. fi
  13. COMMAND=$1
  14. shift 1
  15. INPUTS="$*"
  16. SCHED_NAME=parallel-$CIRCLE_PROJECT_USERNAME-$CIRCLE_PROJECT_REPONAME-$CIRCLE_BUILD_NUM
  17. INPUTS=$(echo "$INPUTS" | python "../tools/sched" sched "$SCHED_NAME" "$CIRCLE_NODE_TOTAL" "$CIRCLE_NODE_INDEX")
  18. echo Doing "$INPUTS"
  19. for INPUT in $INPUTS; do
  20. START=$(date +%s)
  21. $COMMAND "$INPUT"
  22. END=$(date +%s)
  23. RUNTIME=$((END - START))
  24. python "../tools/sched" time "$INPUT" "$RUNTIME"
  25. done