parallel_run 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Rakefile +2 -0
- data/Readme.markdown +65 -0
- data/lib/parallel_run.rb +11 -3
- data/parallel_run.gemspec +1 -1
- metadata +49 -62
data/.gitignore
ADDED
data/Rakefile
ADDED
data/Readme.markdown
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Parallel_run
|
2
|
+
|
3
|
+
## Why ?
|
4
|
+
|
5
|
+
I often need to run a lot of commands in parallel. These commands can be slow (> 10 minutes), and have a very verbose output.
|
6
|
+
In case of error
|
7
|
+
* I don't known which command fails
|
8
|
+
* I cannot differentiate output of the differents commands
|
9
|
+
* I do not have any timestamp about command execution
|
10
|
+
|
11
|
+
`parallel_run` solve that !
|
12
|
+
|
13
|
+
## How to use it
|
14
|
+
|
15
|
+
### Installation
|
16
|
+
|
17
|
+
gem install parallel_run
|
18
|
+
|
19
|
+
### Examples
|
20
|
+
|
21
|
+
Launch in parallel `echo a`, `echo b`, `echo c`
|
22
|
+
|
23
|
+
parallel_run --command "echo %v" a b c
|
24
|
+
|
25
|
+
Launch ruby tests in parallels
|
26
|
+
|
27
|
+
parallel_run --command "ruby -I. %v" tests/*.rb
|
28
|
+
|
29
|
+
Launch ruby tests in parallels and change line prefix to display only test name
|
30
|
+
|
31
|
+
parallel_run --command "ruby -I. %v" --prefix "%b" tests/*.rb
|
32
|
+
|
33
|
+
Launch full-upgrade on multiple servers in parallel
|
34
|
+
|
35
|
+
cat servers_list | xargs parallel_run --command "ssh root@%v aptitude full-upgrade -y"
|
36
|
+
|
37
|
+
Why can it be better than [pssh](http://www.theether.org/pssh/) ?
|
38
|
+
* `parallel_run` will display the list of failing servers at the end
|
39
|
+
* outputs are displayed in real time
|
40
|
+
* all outputs are in the console and can be easily analyzed in a Jenkins output
|
41
|
+
|
42
|
+
I can also use [capistrano](https://github.com/capistrano/capistrano/wiki), but it's more complicated to setup.
|
43
|
+
|
44
|
+
### Exit code
|
45
|
+
|
46
|
+
`parallel_run` will return an exit code 0 only if all commands return an exit code of 0.
|
47
|
+
|
48
|
+
## Options
|
49
|
+
|
50
|
+
$ parallel_run --help
|
51
|
+
Usage: parallel_run [options] values
|
52
|
+
-v, --verbose Output more information
|
53
|
+
-c, --command COMMAND Command to execute. You can use values (see below). Default value is '%v'.
|
54
|
+
-p, --prefix PREFIX Prefix for each line. You can use values (see below). Default value is '%v'.
|
55
|
+
-t, --time_format TIME_FORMAT Time format to use for each line. Default value is %H:%M:%S
|
56
|
+
--padding-size PADDING_SIZE Padding size for prefix. Default value is 20}
|
57
|
+
-h, --help Display this screen
|
58
|
+
Values can be used directly in command or prefix directly by using %v.
|
59
|
+
You can apply some function in values before using it :
|
60
|
+
* %v no function
|
61
|
+
* %b apply basename function
|
62
|
+
* %d apply dirname function
|
63
|
+
* %k return the index of value in command line values
|
64
|
+
|
65
|
+
|
data/lib/parallel_run.rb
CHANGED
@@ -6,7 +6,7 @@ DEFAULT_TIME_FORMAT = "%H:%M:%S"
|
|
6
6
|
DEFAULT_PADDING_SIZE = 20
|
7
7
|
|
8
8
|
$options = {}
|
9
|
-
|
9
|
+
|
10
10
|
optparse = OptionParser.new do|opts|
|
11
11
|
opts.banner = "Usage: parallel_run [options] values"
|
12
12
|
|
@@ -35,6 +35,11 @@ optparse = OptionParser.new do|opts|
|
|
35
35
|
$options[:padding_size] = c.to_i
|
36
36
|
end
|
37
37
|
|
38
|
+
$options[:shell] = ENV['SHELL']
|
39
|
+
opts.on('--shell SHELL', "Shell to be used for launching command (default $SHELL)") do |c|
|
40
|
+
$options[:shell] = c
|
41
|
+
end
|
42
|
+
|
38
43
|
opts.on('-h', '--help', 'Display this screen' ) do
|
39
44
|
puts opts
|
40
45
|
puts "Values can be used directly in command or prefix directly by using %v."
|
@@ -72,7 +77,8 @@ ARGV.each_with_index.to_a.peach do |f, index|
|
|
72
77
|
c = replace $options[:command], f, index
|
73
78
|
prefix = replace $options[:prefix], f, index
|
74
79
|
output("Lauching command for #{f} : #{c}", prefix) if $options[:verbose]
|
75
|
-
|
80
|
+
full_cmd = "#{$options[:shell]} -c \"#{c.gsub(/"/, "\\\"")}\""
|
81
|
+
status = POpen4::popen4(full_cmd, 'r') do |stdout, stderr, stdin, pid|
|
76
82
|
[stdout, stderr].peach do |io|
|
77
83
|
flow = io == stderr ? "err" : "out"
|
78
84
|
while !io.eof?
|
@@ -89,7 +95,9 @@ end
|
|
89
95
|
|
90
96
|
ok = true
|
91
97
|
result.each do |k, v|
|
92
|
-
if v[:status].
|
98
|
+
if v[:status].nil?
|
99
|
+
output "Command failed : #{k} [#{v[:command]}] : unable to launch command", "master"
|
100
|
+
elsif v[:status].exitstatus != 0
|
93
101
|
ok = false
|
94
102
|
output "Command failed : #{k} [#{v[:command]}] : exit code #{v[:status].exitstatus}", "master"
|
95
103
|
end
|
data/parallel_run.gemspec
CHANGED
metadata
CHANGED
@@ -1,100 +1,87 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel_run
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: "0.1"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Bertrand Paquet
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: popen4
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 31
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 1
|
31
|
-
- 2
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
32
21
|
version: 0.1.2
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: peach
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: peach
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.4'
|
48
38
|
type: :runtime
|
49
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.4'
|
50
46
|
description: Launch shell commands in parallel, capturing stdout and stderr
|
51
|
-
email:
|
47
|
+
email:
|
52
48
|
- bertrand.paquet@gmail.com
|
53
|
-
executables:
|
49
|
+
executables:
|
54
50
|
- parallel_run
|
55
51
|
extensions: []
|
56
|
-
|
57
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
58
53
|
- Readme.markdown
|
59
|
-
files:
|
54
|
+
files:
|
55
|
+
- .gitignore
|
60
56
|
- Gemfile
|
61
57
|
- Gemfile.lock
|
58
|
+
- Rakefile
|
62
59
|
- Readme.markdown
|
63
60
|
- bin/parallel_run
|
64
61
|
- lib/parallel_run.rb
|
65
62
|
- parallel_run.gemspec
|
66
63
|
homepage: http://github.com/bpaquet/parallel_run
|
67
64
|
licenses: []
|
68
|
-
|
69
65
|
post_install_message:
|
70
66
|
rdoc_options: []
|
71
|
-
|
72
|
-
require_paths:
|
67
|
+
require_paths:
|
73
68
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
70
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
|
81
|
-
- 0
|
82
|
-
version: "0"
|
83
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
76
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
version: "0"
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
92
81
|
requirements: []
|
93
|
-
|
94
82
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.8.
|
83
|
+
rubygems_version: 1.8.24
|
96
84
|
signing_key:
|
97
85
|
specification_version: 3
|
98
86
|
summary: Launch shell commands in parallel, capturing stdout and stderr
|
99
87
|
test_files: []
|
100
|
-
|