parallizer 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/parallizer.rb +19 -7
- data/lib/parallizer/version.rb +1 -1
- data/spec/parallizer_spec.rb +12 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/parallizer.rb
CHANGED
@@ -4,7 +4,25 @@ require 'parallizer/proxy'
|
|
4
4
|
require 'parallizer/method_call_notifier'
|
5
5
|
|
6
6
|
class Parallizer
|
7
|
-
|
7
|
+
DEFAULT_WORK_QUEUE_SIZE = 10
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def work_queue_size
|
11
|
+
work_queue.max_threads
|
12
|
+
end
|
13
|
+
|
14
|
+
def work_queue_size=(size)
|
15
|
+
work_queue = Thread.current[:parallizer_work_queue]
|
16
|
+
if work_queue.nil? || work_queue.max_threads != size
|
17
|
+
Thread.current[:parallizer_work_queue] = WorkQueue.new(size)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def work_queue
|
22
|
+
# TODO: share the work queue among calling threads
|
23
|
+
Thread.current[:parallizer_work_queue] ||= WorkQueue.new(DEFAULT_WORK_QUEUE_SIZE)
|
24
|
+
end
|
25
|
+
end
|
8
26
|
|
9
27
|
attr_reader :calls, :call_infos, :client, :proxy, :options
|
10
28
|
|
@@ -31,7 +49,6 @@ class Parallizer
|
|
31
49
|
return if call_infos[method_name_and_args]
|
32
50
|
|
33
51
|
call_info = {
|
34
|
-
:complete? => false,
|
35
52
|
:result => nil,
|
36
53
|
:exception => nil,
|
37
54
|
:retries => options[:retries]
|
@@ -49,11 +66,6 @@ class Parallizer
|
|
49
66
|
|
50
67
|
private
|
51
68
|
|
52
|
-
def self.work_queue
|
53
|
-
# TODO: share the work queue among calling threads
|
54
|
-
Thread.current[:parallizer_work_queue] ||= WorkQueue.new(WORK_QUEUE_SIZE)
|
55
|
-
end
|
56
|
-
|
57
69
|
def execute
|
58
70
|
call_infos.each do |method_name_and_args, call_info|
|
59
71
|
Parallizer.work_queue.enqueue_b do
|
data/lib/parallizer/version.rb
CHANGED
data/spec/parallizer_spec.rb
CHANGED
@@ -185,6 +185,18 @@ describe Parallizer do
|
|
185
185
|
@execute_result.message.should == 'an error'
|
186
186
|
end
|
187
187
|
end
|
188
|
+
|
189
|
+
describe "#work_queue_size" do
|
190
|
+
it "should be the default size when not specified" do
|
191
|
+
Parallizer.work_queue_size.should == Parallizer::DEFAULT_WORK_QUEUE_SIZE
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should have max threads equal to specified size" do
|
195
|
+
size = rand(2..5)
|
196
|
+
Parallizer.work_queue_size = size
|
197
|
+
Parallizer.work_queue.max_threads.should == size
|
198
|
+
end
|
199
|
+
end
|
188
200
|
|
189
201
|
## Unable to repro after switch to using ThreadPool instead of work_queue gem
|
190
202
|
# context "with multiple threads making calls to proxy before worker executed" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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: 2012-
|
12
|
+
date: 2012-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: work_queue
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash:
|
114
|
+
hash: 1371680506904516612
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
segments:
|
122
122
|
- 0
|
123
|
-
hash:
|
123
|
+
hash: 1371680506904516612
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project: parallizer
|
126
126
|
rubygems_version: 1.8.24
|