parallizer 0.4.2 → 0.4.3
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/Gemfile.lock +3 -1
- data/lib/parallizer.rb +18 -20
- data/lib/parallizer/proxy.rb +0 -1
- data/lib/parallizer/version.rb +1 -1
- data/parallizer.gemspec +2 -0
- data/spec/parallizer_spec.rb +6 -6
- metadata +21 -5
- data/lib/parallizer/method_call_notifier.rb +0 -15
data/Gemfile.lock
CHANGED
@@ -3,6 +3,7 @@ PATH
|
|
3
3
|
specs:
|
4
4
|
parallizer (0.4.2)
|
5
5
|
celluloid (~> 0.11.0)
|
6
|
+
hanging_methods (~> 0.0.1)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
@@ -11,7 +12,8 @@ GEM
|
|
11
12
|
celluloid (0.11.1)
|
12
13
|
timers (>= 1.0.0)
|
13
14
|
diff-lcs (1.1.3)
|
14
|
-
|
15
|
+
hanging_methods (0.0.1)
|
16
|
+
rake (10.1.0)
|
15
17
|
rspec (2.9.0)
|
16
18
|
rspec-core (~> 2.9.0)
|
17
19
|
rspec-expectations (~> 2.9.0)
|
data/lib/parallizer.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require 'celluloid'
|
2
2
|
Celluloid.logger = nil
|
3
|
+
require 'hanging_methods'
|
3
4
|
require 'parallizer/version'
|
4
5
|
require 'parallizer/proxy'
|
5
6
|
require 'parallizer/worker'
|
6
|
-
require 'parallizer/method_call_notifier'
|
7
7
|
|
8
8
|
class Parallizer
|
9
|
+
include HangingMethods
|
9
10
|
DEFAULT_WORK_QUEUE_SIZE = 10
|
10
11
|
|
12
|
+
add_hanging_method :add, :after_invocation => :add_invoked
|
13
|
+
|
11
14
|
class << self
|
12
15
|
def work_queue_size
|
13
16
|
@work_queue_size || DEFAULT_WORK_QUEUE_SIZE
|
@@ -37,28 +40,12 @@ class Parallizer
|
|
37
40
|
@call_infos = {}
|
38
41
|
end
|
39
42
|
|
40
|
-
def add
|
41
|
-
::Parallizer::MethodCallNotifier.new do |*args|
|
42
|
-
add_call(*args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
43
|
def calls
|
47
44
|
@call_infos.keys
|
48
45
|
end
|
49
46
|
|
50
47
|
def add_call(method_name, *args)
|
51
|
-
|
52
|
-
|
53
|
-
method_name_and_args = [method_name.to_sym, *args]
|
54
|
-
return if call_infos[method_name_and_args]
|
55
|
-
|
56
|
-
call_info = {
|
57
|
-
:future => ::Parallizer::work_queue.future(:run, @client, method_name, args, options),
|
58
|
-
:result => nil,
|
59
|
-
:exception => nil
|
60
|
-
}
|
61
|
-
call_infos[method_name_and_args] = call_info
|
48
|
+
add.send(method_name, *args)
|
62
49
|
end
|
63
50
|
|
64
51
|
def create_proxy
|
@@ -80,12 +67,23 @@ class Parallizer
|
|
80
67
|
end
|
81
68
|
|
82
69
|
private
|
70
|
+
|
71
|
+
def add_invoked(method_name_and_args)
|
72
|
+
raise ArgumentError, "Cannot add calls after proxy has been generated" if @proxy
|
73
|
+
|
74
|
+
return if call_infos[method_name_and_args]
|
75
|
+
|
76
|
+
call_info = {
|
77
|
+
:future => ::Parallizer::work_queue.future(:run, @client, method_name_and_args.first, method_name_and_args[1..-1], options),
|
78
|
+
:result => nil,
|
79
|
+
:exception => nil
|
80
|
+
}
|
81
|
+
call_infos[method_name_and_args] = call_info
|
82
|
+
end
|
83
83
|
|
84
84
|
def execute
|
85
85
|
call_infos.each do |method_name_and_args, call_info|
|
86
86
|
call_info.merge!(call_info[:future].value)
|
87
87
|
end
|
88
|
-
|
89
|
-
::Parallizer::Proxy.new(client, call_infos)
|
90
88
|
end
|
91
89
|
end
|
data/lib/parallizer/proxy.rb
CHANGED
data/lib/parallizer/version.rb
CHANGED
data/parallizer.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://github.com/michaelgpearce/parallizer"
|
12
12
|
s.summary = %q{Execute your service layer in parallel}
|
13
13
|
s.description = %q{Execute your service layer in parallel.}
|
14
|
+
s.license = "MIT"
|
14
15
|
|
15
16
|
s.rubyforge_project = "parallizer"
|
16
17
|
|
@@ -19,6 +20,7 @@ Gem::Specification.new do |s|
|
|
19
20
|
s.require_paths = ["lib"]
|
20
21
|
|
21
22
|
s.add_dependency 'celluloid', '~> 0.11.0'
|
23
|
+
s.add_dependency 'hanging_methods', '~> 0.0.1'
|
22
24
|
s.add_development_dependency 'rake'
|
23
25
|
s.add_development_dependency 'rspec', '~> 2.9.0'
|
24
26
|
s.add_development_dependency 'always_execute', '~> 0.1.1'
|
data/spec/parallizer_spec.rb
CHANGED
@@ -4,11 +4,11 @@ describe Parallizer do
|
|
4
4
|
class TestObject
|
5
5
|
def a_method(arg)
|
6
6
|
@a_method ||= {}
|
7
|
-
@a_method[arg] ||= rand(
|
7
|
+
@a_method[arg] ||= rand(100)
|
8
8
|
end
|
9
9
|
|
10
10
|
def another_method
|
11
|
-
@another_method ||= rand(
|
11
|
+
@another_method ||= rand(100)
|
12
12
|
end
|
13
13
|
|
14
14
|
def current_thread
|
@@ -22,11 +22,11 @@ describe Parallizer do
|
|
22
22
|
|
23
23
|
class AnotherTestObject
|
24
24
|
def a_method
|
25
|
-
@a_method ||= rand(
|
25
|
+
@a_method ||= rand(100)
|
26
26
|
end
|
27
27
|
|
28
28
|
def another_method
|
29
|
-
@another_method ||= rand(
|
29
|
+
@another_method ||= rand(100)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -47,6 +47,7 @@ describe Parallizer do
|
|
47
47
|
|
48
48
|
describe "#add_call" do
|
49
49
|
before do
|
50
|
+
@method = :a_method
|
50
51
|
@client = TestObject.new
|
51
52
|
@parallizer = Parallizer.new(@client)
|
52
53
|
end
|
@@ -67,7 +68,6 @@ describe Parallizer do
|
|
67
68
|
|
68
69
|
context "with call already added" do
|
69
70
|
before do
|
70
|
-
@method = :a_method
|
71
71
|
@parallizer.add_call(@method, 'arg')
|
72
72
|
@call_info = @parallizer.call_infos[[@method, 'arg']]
|
73
73
|
@call_info.should_not be_nil
|
@@ -226,7 +226,7 @@ describe Parallizer do
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it "should have max threads equal to specified size after requesting the work queue" do
|
229
|
-
size = rand(
|
229
|
+
size = 2 + rand(3)
|
230
230
|
Parallizer.work_queue_size = size
|
231
231
|
Parallizer.work_queue
|
232
232
|
Thread.current[:parallizer_work_queue_size].should == size
|
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.4.
|
4
|
+
version: 0.4.3
|
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: 2013-07-
|
12
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.11.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: hanging_methods
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.1
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +105,6 @@ files:
|
|
89
105
|
- README.md
|
90
106
|
- Rakefile
|
91
107
|
- lib/parallizer.rb
|
92
|
-
- lib/parallizer/method_call_notifier.rb
|
93
108
|
- lib/parallizer/proxy.rb
|
94
109
|
- lib/parallizer/version.rb
|
95
110
|
- lib/parallizer/worker.rb
|
@@ -99,7 +114,8 @@ files:
|
|
99
114
|
- spec/parallizer_spec.rb
|
100
115
|
- spec/spec_helper.rb
|
101
116
|
homepage: http://github.com/michaelgpearce/parallizer
|
102
|
-
licenses:
|
117
|
+
licenses:
|
118
|
+
- MIT
|
103
119
|
post_install_message:
|
104
120
|
rdoc_options: []
|
105
121
|
require_paths:
|
@@ -118,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
134
|
version: '0'
|
119
135
|
requirements: []
|
120
136
|
rubyforge_project: parallizer
|
121
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.21
|
122
138
|
signing_key:
|
123
139
|
specification_version: 3
|
124
140
|
summary: Execute your service layer in parallel
|