Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Launch multiple commands in parallel
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
tests
.gitignore
Gemfile
Gemfile.lock
Rakefile
Readme.markdown
parallel_run.gemspec

Readme.markdown

Parallel_run

Why ?

I often need to run a lot of commands in parallel. These commands can be slow (> 10 minutes), and have a very verbose output. In case of error

  • I don't known which command fails
  • I cannot differentiate output of the differents commands
  • I do not have any timestamp about command execution

parallel_run solve that !

How to use it

Installation

gem install parallel_run

Examples

Launch in parallel echo a, echo b, echo c

parallel_run --command "echo %v" a b c

Launch ruby tests in parallels

parallel_run --command "ruby -I. %v" tests/*.rb

Launch ruby tests in parallels and change line prefix to display only test name

parallel_run --command "ruby -I. %v" --prefix "%b" tests/*.rb

Launch full-upgrade on multiple servers in parallel

cat servers_list | xargs parallel_run --command "ssh root@%v aptitude full-upgrade -y"

Why can it be better than pssh ?

  • parallel_run will display the list of failing servers at the end
  • outputs are displayed in real time
  • all outputs are in the console and can be easily analyzed in a Jenkins output

I can also use capistrano, but it's more complicated to setup.

Exit code

parallel_run will return an exit code 0 only if all commands return an exit code of 0.

Options

$ parallel_run --help
Usage: parallel_run [options] values
    -v, --verbose                    Output more information
    -c, --command COMMAND            Command to execute. You can use values (see below). Default value is '%v'.
    -p, --prefix PREFIX              Prefix for each line. You can use values (see below). Default value is '%v'.
    -t, --time_format TIME_FORMAT    Time format to use for each line. Default value is %H:%M:%S
        --padding-size PADDING_SIZE  Padding size for prefix. Default value is 20}
        --workers WORKERS            Number of workers (default number of value)
    -h, --help                       Display this screen
Values can be used directly in command or prefix directly by using %v.
You can apply some function in values before using it :
* %v no function
* %b apply basename function
* %d apply dirname function
* %k return the index of value in command line values
Something went wrong with that request. Please try again.