jobQueue 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -1
- data/bin/prun.rb +8 -4
- data/gemspec +1 -1
- data/lib/jobqueue.rb +8 -3
- data/test/test_jobqueue.rb +1 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -62,7 +62,10 @@ will start 2 parallel searches for ruby files. This is implemented in the
|
|
62
62
|
prun.rb script, which comes with the jobQueue gem. To run each line of a shell
|
63
63
|
script on 10 threads, use:
|
64
64
|
|
65
|
-
prun.rb 10 jobs.sh
|
65
|
+
prun.rb -j 10 jobs.sh
|
66
|
+
|
67
|
+
The '-j' switch is optional. Default is the maximum number of cores. The script
|
68
|
+
accepts multiple files and processes one after another.
|
66
69
|
|
67
70
|
== Support, Issues, Bugs, ...
|
68
71
|
|
data/bin/prun.rb
CHANGED
@@ -9,13 +9,16 @@ require 'jobqueue'
|
|
9
9
|
# ==============================================================================
|
10
10
|
|
11
11
|
nTh = SystemJobs.maxnumber_of_processors
|
12
|
-
options = {:workers => nTh}
|
12
|
+
options = {:workers => nTh,:debug => false}
|
13
13
|
optparse = OptionParser.new do|opts|
|
14
14
|
opts.banner = "Usage: prun.rb [options] command-files"
|
15
15
|
|
16
16
|
opts.separator ""
|
17
|
-
opts.on('-j [
|
18
|
-
options[:workers] = num
|
17
|
+
opts.on('-j [NUM]',"Number of worker threads (default:#{nTh})") do |num|
|
18
|
+
options[:workers] = num.to_i.abs
|
19
|
+
end
|
20
|
+
opts.on('-d','--debug','Print output from workers on stdout') do
|
21
|
+
options[:debug] = true
|
19
22
|
end
|
20
23
|
# This displays the help screen, all programs are
|
21
24
|
# assumed to have this option.
|
@@ -35,7 +38,8 @@ end
|
|
35
38
|
ARGV.each do|f|
|
36
39
|
# read file line per line
|
37
40
|
lines = File.open(f).readlines.map(&:chomp)
|
38
|
-
q = SystemJobs.new(
|
41
|
+
q = SystemJobs.new(options[:workers],options[:debug])
|
42
|
+
puts q.workers if options[:debug]
|
39
43
|
lines.each {|line| q.push(line) }
|
40
44
|
q.run
|
41
45
|
end
|
data/gemspec
CHANGED
data/lib/jobqueue.rb
CHANGED
@@ -12,9 +12,10 @@ class JobQueue
|
|
12
12
|
attr_reader :workers, :threads
|
13
13
|
|
14
14
|
# Create a new queue qith a given number of worker threads
|
15
|
-
def initialize(nWorkers)
|
15
|
+
def initialize(nWorkers,debug=false)
|
16
16
|
@workers = nWorkers
|
17
17
|
@queue = Queue.new
|
18
|
+
@debug = debug
|
18
19
|
end
|
19
20
|
|
20
21
|
# borrow some useful methods from Queue class
|
@@ -90,9 +91,13 @@ end
|
|
90
91
|
class SystemJobs < JobQueue
|
91
92
|
def run
|
92
93
|
@threads = (1..@workers).map {|i|
|
93
|
-
Thread.new(@queue) {|q|
|
94
|
+
Thread.new(@queue,@debug) {|q,dbg|
|
94
95
|
until ( q == ( task = q.deq ) )
|
95
|
-
|
96
|
+
if dbg
|
97
|
+
puts IO.popen(task.first).read
|
98
|
+
else
|
99
|
+
IO.popen(task.first)
|
100
|
+
end
|
96
101
|
end
|
97
102
|
}
|
98
103
|
}
|
data/test/test_jobqueue.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jobQueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Run Shell commands or Ruby methods in parallel
|
15
15
|
email: stark.dreamdetective@gmail.com
|