jobQueue 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/prun.rb +1 -1
- data/gemspec +1 -1
- data/lib/jobqueue.rb +2 -5
- data/test/test_jobqueue.rb +38 -0
- metadata +2 -2
data/bin/prun.rb
CHANGED
@@ -39,7 +39,7 @@ ARGV.each do|f|
|
|
39
39
|
# read file line per line
|
40
40
|
lines = File.open(f).readlines.map(&:chomp)
|
41
41
|
q = SystemJobs.new(options[:workers],options[:debug])
|
42
|
-
puts q.workers
|
42
|
+
puts "Run with #{q.workers} threads"
|
43
43
|
lines.each {|line| q.push(line) }
|
44
44
|
q.run
|
45
45
|
end
|
data/gemspec
CHANGED
data/lib/jobqueue.rb
CHANGED
@@ -93,11 +93,8 @@ class SystemJobs < JobQueue
|
|
93
93
|
@threads = (1..@workers).map {|i|
|
94
94
|
Thread.new(@queue,@debug) {|q,dbg|
|
95
95
|
until ( q == ( task = q.deq ) )
|
96
|
-
|
97
|
-
|
98
|
-
else
|
99
|
-
IO.popen(task.first)
|
100
|
-
end
|
96
|
+
ret = IO.popen(task.first).read
|
97
|
+
#puts ret if dbg
|
101
98
|
end
|
102
99
|
}
|
103
100
|
}
|
data/test/test_jobqueue.rb
CHANGED
@@ -199,4 +199,42 @@ class TestJobQueue < Test::Unit::TestCase
|
|
199
199
|
@jq.run
|
200
200
|
(0..size).each {|i| assert_equal(2*i,a.h[i]) }
|
201
201
|
end
|
202
|
+
|
203
|
+
def test_Shell
|
204
|
+
return true if @jq
|
205
|
+
script = Tempfile.open("jobQueue")
|
206
|
+
(1..8).each {|i| script << "date;echo #{i}; sleep 1\n" }
|
207
|
+
script.close
|
208
|
+
#puts script.path
|
209
|
+
#puts IO.popen("cat "+script.path).read
|
210
|
+
|
211
|
+
# test in debug mode
|
212
|
+
tstart = Time.new
|
213
|
+
puts IO.popen("bin/prun.rb -d -j 4 #{script.path}").read
|
214
|
+
tend = Time.new
|
215
|
+
trun = tend - tstart
|
216
|
+
assert(2.0 < trun,"Test (debug mode) runs to fast: #{trun}, lower limit 2")
|
217
|
+
assert(trun < 3 ,"Test (debug mode) runs to slow: #{trun}, upper limit 3")
|
218
|
+
# test in normal mode
|
219
|
+
tstart = Time.new
|
220
|
+
puts IO.popen("bin/prun.rb -j 4 #{script.path}").read
|
221
|
+
tend = Time.new
|
222
|
+
trun = tend - tstart
|
223
|
+
assert(2.0 < trun,"Test (normal mode) runs to fast: #{trun}, lower limit 2")
|
224
|
+
assert(trun < 3 ,"Test (normal mode) runs to slow: #{trun}, upper limit 3")
|
225
|
+
# with 8 threads
|
226
|
+
tstart = Time.new
|
227
|
+
puts IO.popen("bin/prun.rb -d -j 8 #{script.path}").read
|
228
|
+
tend = Time.new
|
229
|
+
trun = tend - tstart
|
230
|
+
assert(1.0 < trun,"Test (debug mode) runs to fast: #{trun}, lower limit 1")
|
231
|
+
assert(trun < 2.0,"Test (debug mode) runs to slow: #{trun}, lower limit 2")
|
232
|
+
# test in normal mode
|
233
|
+
tstart = Time.new
|
234
|
+
puts IO.popen("bin/prun.rb -j 8 #{script.path}").read
|
235
|
+
tend = Time.new
|
236
|
+
trun = tend - tstart
|
237
|
+
assert(1.0 < trun,"Test (debug mode) runs to fast: #{trun}, lower limit 1")
|
238
|
+
assert(trun < 2.0,"Test (debug mode) runs to slow: #{trun}, lower limit 2")
|
239
|
+
end
|
202
240
|
end
|
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.5
|
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:
|
12
|
+
date: 2012-01-17 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
|