1. Always Set a Default (+4)
1. Always Set a Default
PARALLEL="${PARALLEL:-5}"
2. Validate Input
[[ $PARALLEL -gt 0 ]] || die "Parallelism must be positive"
[[ $PARALLEL -le 50 ]] || log_warning "High parallelism may overwhelm system"
3. Handle Failures Gracefully
# Don't use set -e with xargs - it will mask failures
# Instead, track failures explicitly
4. Log Everything
# Create per-task logs for debugging
log_file="$LOG_DIR/task_$(date +%s)_$$.log"
5. Clean Up Resources
trap cleanup EXIT INT TERM