queuel 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/queuel/base/poller.rb +29 -3
- data/lib/queuel/base/queue.rb +4 -0
- data/lib/queuel/configurator.rb +1 -0
- data/lib/queuel/version.rb +1 -1
- data/lib/queuel.rb +1 -0
- data/spec/support/poller_shared_example.rb +17 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/queuel/base/poller.rb
CHANGED
@@ -14,6 +14,8 @@ module Queuel
|
|
14
14
|
self.inst_block = param_block
|
15
15
|
self.tries = 0
|
16
16
|
self.continue_looping = true
|
17
|
+
self.pool_tasks = 0
|
18
|
+
self.mutex = Mutex.new
|
17
19
|
end
|
18
20
|
|
19
21
|
def poll
|
@@ -30,6 +32,8 @@ module Queuel
|
|
30
32
|
attr_accessor :tries
|
31
33
|
attr_accessor :workers
|
32
34
|
attr_accessor :inst_block
|
35
|
+
attr_accessor :mutex
|
36
|
+
attr_accessor :pool_tasks
|
33
37
|
|
34
38
|
private
|
35
39
|
attr_accessor :master
|
@@ -39,8 +43,8 @@ module Queuel
|
|
39
43
|
attr_accessor :continue_looping
|
40
44
|
|
41
45
|
def register_trappers
|
42
|
-
trap(:SIGINT) { shutdown }
|
43
|
-
trap(:INT) { shutdown }
|
46
|
+
trap(:SIGINT) { Thread.new{shutdown}.join }
|
47
|
+
trap(:INT) { Thread.new{shutdown}.join }
|
44
48
|
end
|
45
49
|
|
46
50
|
def log_action(verb, subject, level = :debug)
|
@@ -93,8 +97,11 @@ module Queuel
|
|
93
97
|
end
|
94
98
|
|
95
99
|
def process_on_thread
|
100
|
+
return if pool_full?
|
101
|
+
increment_pool_task_count
|
96
102
|
pool.process do
|
97
103
|
process_message
|
104
|
+
decrement_pool_task_count
|
98
105
|
end
|
99
106
|
end
|
100
107
|
|
@@ -146,7 +153,7 @@ module Queuel
|
|
146
153
|
end
|
147
154
|
|
148
155
|
def sleep_time
|
149
|
-
tries < 30 ? ((start_sleep_time + increment_sleep_time) * tries) : 3
|
156
|
+
tries < 30 && !pool_full? ? ((start_sleep_time + increment_sleep_time) * tries) : 3
|
150
157
|
end
|
151
158
|
|
152
159
|
def reset_tries
|
@@ -156,6 +163,25 @@ module Queuel
|
|
156
163
|
def tried
|
157
164
|
self.tries += 1
|
158
165
|
end
|
166
|
+
|
167
|
+
def pool_full?
|
168
|
+
return false unless queue.max_pool_tasks
|
169
|
+
self.mutex.synchronize{
|
170
|
+
self.pool_tasks > queue.max_pool_tasks
|
171
|
+
}
|
172
|
+
end
|
173
|
+
|
174
|
+
def increment_pool_task_count
|
175
|
+
self.mutex.synchronize{
|
176
|
+
self.pool_tasks += 1
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
def decrement_pool_task_count
|
181
|
+
self.mutex.synchronize{
|
182
|
+
self.pool_tasks -= 1
|
183
|
+
}
|
184
|
+
end
|
159
185
|
end
|
160
186
|
end
|
161
187
|
end
|
data/lib/queuel/base/queue.rb
CHANGED
data/lib/queuel/configurator.rb
CHANGED
@@ -54,6 +54,7 @@ module Queuel
|
|
54
54
|
param :engine
|
55
55
|
param :default_queue
|
56
56
|
param :receiver_threads, default: 1
|
57
|
+
param :max_pool_tasks, deafult: nil
|
57
58
|
|
58
59
|
param :decode_by_default, default: true, boolean: true
|
59
60
|
param :decoder, default: Queuel::Serialization::Json::Decoder, validate: {
|
data/lib/queuel/version.rb
CHANGED
data/lib/queuel.rb
CHANGED
@@ -54,17 +54,33 @@ shared_examples "a poller" do
|
|
54
54
|
before do
|
55
55
|
subject.stub quit_on_empty?: true
|
56
56
|
queue.stub(:peek).and_return [message], nil
|
57
|
-
queue.stub(:approximate_number_of_messages).and_return 1, 0
|
58
57
|
subject.stub(:pop_new_message).and_return(message, nil)
|
58
|
+
|
59
59
|
end
|
60
60
|
|
61
61
|
it "can poll" do
|
62
62
|
not_for_null do
|
63
|
+
queue.stub(:approximate_number_of_messages).and_return 1, 0
|
64
|
+
queue.stub(:max_pool_tasks).and_return nil
|
65
|
+
block.should_receive(:call).once.and_return true
|
66
|
+
message.should_receive(:delete)
|
67
|
+
subject.poll
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "can poll with poll limit" do
|
72
|
+
not_for_null do
|
73
|
+
queue.stub(:approximate_number_of_messages).and_return 2, 1, 0
|
74
|
+
queue.stub(:max_pool_tasks).and_return 1
|
63
75
|
block.should_receive(:call).once.and_return true
|
64
76
|
message.should_receive(:delete)
|
77
|
+
subject.should_receive(:increment_pool_task_count).at_least(1).times
|
78
|
+
subject.should_receive(:decrement_pool_task_count).once
|
65
79
|
subject.poll
|
66
80
|
end
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|
84
|
+
|
85
|
+
|
70
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queuel
|
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: 2014-
|
12
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -403,7 +403,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
403
403
|
version: '0'
|
404
404
|
segments:
|
405
405
|
- 0
|
406
|
-
hash:
|
406
|
+
hash: 2799856910334215195
|
407
407
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
408
408
|
none: false
|
409
409
|
requirements:
|
@@ -412,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
412
412
|
version: '0'
|
413
413
|
segments:
|
414
414
|
- 0
|
415
|
-
hash:
|
415
|
+
hash: 2799856910334215195
|
416
416
|
requirements: []
|
417
417
|
rubyforge_project:
|
418
418
|
rubygems_version: 1.8.23.2
|