work_queue 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f26271fcef114e2b126329e98c5805a73f67e397
4
+ data.tar.gz: 9b57c49e5f8a361f823b8fbabfc693782b1f5f89
5
+ SHA512:
6
+ metadata.gz: 6e1249bf45fc675d1a3cc80488e2c3912080a449fcd84df15342f24026ca65c69b7ce62244774920e031a4a4a23d5c3ef9deb76b7b4af73eaedee5aec0a1c560
7
+ data.tar.gz: 0b3da201d24636d7982c971502db6200d21a7147c2964657ad219a41d4c4ebc14bf1caf70064b6ae331c7a1f4f7bf660353825431b1e5f41c7db8900863f403a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Miguel Fonseca
1
+ Copyright (c) 2014 Miguel Fonseca
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
16
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
19
+ THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'lib/work_queue'
1
+ require "rubygems"
2
+ require "rake"
3
+ require "rake/clean"
4
+ require_relative "lib/work_queue"
5
5
 
6
6
  # Load all rakefile extensions
7
7
  Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].each { |ext| load ext }
8
8
 
9
9
  # Set default task
10
- task :default => ["test:unit"]
10
+ task :default => ["test:unit"]
@@ -1,11 +1,11 @@
1
- require 'thread'
2
- require 'monitor'
1
+ require "thread"
2
+ require "monitor"
3
3
 
4
4
  ##
5
5
  # A tunable work queue, designed to coordinate work between a producer and a pool of worker threads.
6
6
  #
7
7
  class WorkQueue
8
- VERSION = "2.5.3"
8
+ VERSION = "2.5.4"
9
9
 
10
10
  ##
11
11
  # Creates an empty work queue with the desired parameters.
@@ -20,13 +20,13 @@ class WorkQueue
20
20
  # wq = WorkQueue.new nil, 20
21
21
  # wq = WorkQueue.new 10, 20
22
22
  #
23
- def initialize(max_threads=nil, max_tasks=nil)
23
+ def initialize(max_threads = nil, max_tasks = nil)
24
24
  self.max_threads = max_threads
25
25
  self.max_tasks = max_tasks
26
- @threads = Array.new
26
+ @threads = []
27
27
  @threads_waiting = 0
28
28
  @threads.extend MonitorMixin
29
- @tasks = Array.new
29
+ @tasks = []
30
30
  @tasks.extend MonitorMixin
31
31
  @task_enqueued = @tasks.new_cond
32
32
  @task_dequeued = @tasks.new_cond
@@ -148,7 +148,7 @@ class WorkQueue
148
148
  def kill
149
149
  @tasks.synchronize do
150
150
  @threads.synchronize do
151
- @threads.each { |thread| thread.exit }
151
+ @threads.each(&:exit)
152
152
  @threads.clear
153
153
  @threads_waiting = 0
154
154
  end
@@ -165,16 +165,16 @@ class WorkQueue
165
165
  # Sets the maximum number of worker threads.
166
166
  #
167
167
  def max_threads=(value)
168
- raise ArgumentError, "the maximum number of threads must be positive" if value and value <= 0
169
- @max_threads = value || 1.0/0
168
+ fail ArgumentError, "the maximum number of threads must be positive" if value && value <= 0
169
+ @max_threads = value || 1.0 / 0
170
170
  end
171
171
 
172
172
  ##
173
173
  # Sets the maximum number of queued tasks.
174
174
  #
175
175
  def max_tasks=(value)
176
- raise ArgumentError, "the maximum number of tasks must be positive" if value and value <= 0
177
- @max_tasks = value || 1.0/0
176
+ fail ArgumentError, "the maximum number of tasks must be positive" if value && value <= 0
177
+ @max_tasks = value || 1.0 / 0
178
178
  end
179
179
 
180
180
  ##
@@ -207,20 +207,18 @@ class WorkQueue
207
207
  # Repeatedly process the tasks queue.
208
208
  #
209
209
  def run
210
- begin
211
- loop do
212
- proc, params = dequeue
213
- begin
214
- proc.call(*params)
215
- rescue Exception => e
216
- # Suppress Exception
217
- end
218
- conclude
219
- end
220
- ensure
221
- @threads.synchronize do
222
- @threads.delete Thread.current
210
+ loop do
211
+ proc, params = dequeue
212
+ begin
213
+ proc.call(*params)
214
+ rescue => e
215
+ STDERR.puts e
223
216
  end
217
+ conclude
218
+ end
219
+ ensure
220
+ @threads.synchronize do
221
+ @threads.delete Thread.current
224
222
  end
225
223
  end
226
224
 
@@ -247,4 +245,4 @@ class WorkQueue
247
245
  @task_completed.broadcast
248
246
  end
249
247
  end
250
- end
248
+ end
@@ -1,11 +1,11 @@
1
- require 'rake/testtask'
1
+ require "rake/testtask"
2
2
 
3
3
  namespace(:test) do
4
4
  # For a list of all attributes refer to http://rake.rubyforge.org/classes/Rake/TestTask.html
5
5
  Rake::TestTask.new(:unit) do |t|
6
6
  t.libs << "test"
7
- t.test_files = FileList['test/tc_*.rb']
7
+ t.test_files = FileList["test/tc_*.rb"]
8
8
  t.verbose = true
9
9
  t.warning = true
10
10
  end
11
- end
11
+ end
@@ -1,17 +1,17 @@
1
- require 'test/unit'
2
- require 'lib/work_queue'
1
+ require "test/unit"
2
+ require_relative "../lib/work_queue"
3
3
 
4
- class TC_WorkQueue < Test::Unit::TestCase
4
+ class TestWorkQueue < Test::Unit::TestCase
5
5
  def test_enqueue_proc
6
- s = String.new
6
+ s = ""
7
7
  wq = WorkQueue.new
8
- wq.enqueue_p(Proc.new { |str| str.replace "Hello Proc" }, s)
8
+ wq.enqueue_p(proc { |str| str.replace "Hello Proc" }, s)
9
9
  wq.join
10
10
  assert_equal "Hello Proc", s
11
11
  end
12
12
 
13
13
  def test_enqueue_block
14
- s = String.new
14
+ s = ""
15
15
  wq = WorkQueue.new
16
16
  wq.enqueue_b(s) { |str| str.replace "Hello Block" }
17
17
  wq.join
@@ -19,7 +19,7 @@ class TC_WorkQueue < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_inner_enqueue
22
- s = String.new
22
+ s = ""
23
23
  wq = WorkQueue.new
24
24
  wq.enqueue_b do
25
25
  sleep 0.01
@@ -41,7 +41,7 @@ class TC_WorkQueue < Test::Unit::TestCase
41
41
  end
42
42
 
43
43
  def test_max_threads
44
- wq = WorkQueue.new 1
44
+ wq = WorkQueue.new(1)
45
45
  assert_equal 0, wq.cur_threads
46
46
  wq.enqueue_b { sleep 0.01 }
47
47
  assert_equal 1, wq.cur_threads
@@ -53,12 +53,12 @@ class TC_WorkQueue < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_max_threads_validation
56
- assert_raise(ArgumentError) { WorkQueue.new 0, nil }
57
- assert_raise(ArgumentError) { WorkQueue.new -1, nil }
56
+ assert_raise(ArgumentError) { WorkQueue.new(0, nil) }
57
+ assert_raise(ArgumentError) { WorkQueue.new(-1, nil) }
58
58
  end
59
59
 
60
60
  def test_max_tasks
61
- wq = WorkQueue.new 1, 1
61
+ wq = WorkQueue.new(1, 1)
62
62
  wq.enqueue_b { sleep 0.01 }
63
63
  wq.enqueue_b { sleep 0.01 }
64
64
  assert_equal 1, wq.cur_tasks
@@ -68,45 +68,45 @@ class TC_WorkQueue < Test::Unit::TestCase
68
68
  end
69
69
 
70
70
  def test_max_tasks_validation
71
- assert_raise(ArgumentError) { WorkQueue.new nil, 0 }
72
- assert_raise(ArgumentError) { WorkQueue.new nil, -1 }
71
+ assert_raise(ArgumentError) { WorkQueue.new(nil, 0) }
72
+ assert_raise(ArgumentError) { WorkQueue.new(nil, -1) }
73
73
  end
74
74
 
75
75
  def test_stress
76
76
  i = 0
77
77
  m = Mutex.new
78
- wq = WorkQueue.new 100, 200
79
- (1..1000).each do
80
- wq.enqueue_b {
78
+ wq = WorkQueue.new(100, 200)
79
+ (1..10_000).each do
80
+ wq.enqueue_b do
81
81
  sleep 0.01
82
82
  m.synchronize { i += 1 }
83
- }
83
+ end
84
84
  end
85
85
  wq.join
86
- assert_equal 1000, i
86
+ assert_equal 10_000, i
87
87
  end
88
88
 
89
89
  def test_stress_prolonged
90
90
  i = 0
91
91
  m = Mutex.new
92
- wq = WorkQueue.new 100, 200
93
- (1..1000).each do
94
- wq.enqueue_b {
92
+ wq = WorkQueue.new(100, 200)
93
+ (1..10_000).each do
94
+ wq.enqueue_b do
95
95
  sleep rand(5)
96
96
  m.synchronize { i += 1 }
97
- }
97
+ end
98
98
  end
99
99
  wq.join
100
- assert_equal 1000, i
100
+ assert_equal 10_000, i
101
101
  end
102
102
 
103
103
  def test_kill
104
- s = String.new
104
+ s = ""
105
105
  wq = WorkQueue.new
106
- wq.enqueue_b(s) { |str|
106
+ wq.enqueue_b(s) do |str|
107
107
  sleep 0.1
108
108
  str.replace "Hello"
109
- }
109
+ end
110
110
  wq.kill
111
111
  assert(s.empty?)
112
112
  end
metadata CHANGED
@@ -1,77 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: work_queue
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
6
- segments:
7
- - 2
8
- - 5
9
- - 3
10
- version: 2.5.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.4
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Miguel Fonseca
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-02-23 00:00:00 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
13
  description:
22
14
  email: contact@miguelfonseca.com
23
15
  executables: []
24
-
25
16
  extensions: []
26
-
27
- extra_rdoc_files:
17
+ extra_rdoc_files:
28
18
  - README.rdoc
29
19
  - LICENSE
30
- files:
20
+ files:
31
21
  - LICENSE
32
22
  - Rakefile
33
23
  - README.rdoc
34
24
  - tasks/test.rake
35
- - lib/test.rb
36
25
  - lib/work_queue.rb
37
26
  - test/tc_work_queue.rb
38
27
  homepage: http://github.com/fmmfonseca/work_queue
39
- licenses: []
40
-
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
41
31
  post_install_message:
42
- rdoc_options:
32
+ rdoc_options:
43
33
  - --line-numbers
44
34
  - --inline-source
45
35
  - --main
46
36
  - README.rdoc
47
- require_paths:
37
+ require_paths:
48
38
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 57
55
- segments:
56
- - 1
57
- - 8
58
- - 7
59
- version: 1.8.7
60
- required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.9.3
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
69
49
  requirements: []
70
-
71
50
  rubyforge_project:
72
- rubygems_version: 1.8.22
51
+ rubygems_version: 2.0.14
73
52
  signing_key:
74
- specification_version: 3
75
- summary: A tunable work queue, designed to coordinate work between a producer and a pool of worker threads.
76
- test_files:
53
+ specification_version: 4
54
+ summary: A tunable work queue, designed to coordinate work between a producer and
55
+ a pool of worker threads.
56
+ test_files:
77
57
  - test/tc_work_queue.rb
@@ -1,12 +0,0 @@
1
- require_relative 'work_queue'
2
-
3
- work_queue = WorkQueue.new(1000)
4
-
5
- # Force threads to be available - the work_queue gem seems to not always create the threads
6
- 10000.times do |i|
7
- work_queue.enqueue_b do
8
- a = 2
9
- end
10
- end
11
-
12
- puts "ola"