infopark-politics 0.2.13 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
@@ -80,6 +80,9 @@ module Politics
|
|
80
80
|
register_with_bonjour
|
81
81
|
log.progname = uri
|
82
82
|
log.info { "Registered in group #{group_name} at port #{@port}" }
|
83
|
+
at_exit do
|
84
|
+
cleanup
|
85
|
+
end
|
83
86
|
end
|
84
87
|
|
85
88
|
# Fetch a bucket out of the queue and pass it to the given block to be processed.
|
@@ -224,9 +227,7 @@ module Politics
|
|
224
227
|
end
|
225
228
|
|
226
229
|
def cleanup
|
227
|
-
|
228
|
-
@memcache_client.delete(token) if leader?
|
229
|
-
end
|
230
|
+
@memcache_client.delete(token) if leader?
|
230
231
|
end
|
231
232
|
|
232
233
|
def pause_until_expiry(elapsed)
|
@@ -6,11 +6,10 @@ Politics::log.level = Logger::FATAL
|
|
6
6
|
|
7
7
|
@@memcache_client = nil
|
8
8
|
|
9
|
-
class
|
9
|
+
class UninitializedWorker
|
10
10
|
include Politics::StaticQueueWorker
|
11
11
|
def initialize
|
12
12
|
log.level = Logger::FATAL
|
13
|
-
register_worker 'worker', 10, :iteration_length => 10
|
14
13
|
end
|
15
14
|
|
16
15
|
def start
|
@@ -28,13 +27,38 @@ class Worker
|
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
30
|
+
class Worker < UninitializedWorker
|
31
|
+
def at_exit
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
super
|
36
|
+
register_worker 'worker', 10, :iteration_length => 10
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe UninitializedWorker do
|
41
|
+
before do
|
42
|
+
@@memcache_client = mock('memcache', :set => nil, :get => nil)
|
43
|
+
@worker = UninitializedWorker.new
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should register the removal of the leadership as exit handler" do
|
47
|
+
@worker.should_receive(:at_exit).ordered.and_return {|h| h}
|
48
|
+
handler = @worker.register_worker('worker', 10, :iteration_length => 10)
|
49
|
+
|
50
|
+
@worker.should_receive(:cleanup).ordered
|
51
|
+
handler.call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
31
55
|
describe Worker do
|
32
56
|
before do
|
33
57
|
@@memcache_client = mock('memcache', :set => nil, :get => nil)
|
34
58
|
@worker = Worker.new
|
35
59
|
end
|
36
60
|
|
37
|
-
it "
|
61
|
+
it "should provide 'until_next_iteration' even if nominate was not completed" do
|
38
62
|
@worker.until_next_iteration
|
39
63
|
end
|
40
64
|
|
@@ -291,4 +315,32 @@ describe Worker do
|
|
291
315
|
end
|
292
316
|
end
|
293
317
|
end
|
318
|
+
|
319
|
+
describe "when cleaning up" do
|
320
|
+
before do
|
321
|
+
@worker.stub!(:token).and_return('dcc-group')
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "as leader" do
|
325
|
+
before do
|
326
|
+
@worker.stub!(:leader?).and_return true
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should remove the leadership token" do
|
330
|
+
@@memcache_client.should_receive(:delete).with('dcc-group')
|
331
|
+
@worker.send(:cleanup)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "as follower" do
|
336
|
+
before do
|
337
|
+
@worker.stub!(:leader?).and_return false
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should not remove the leadership token" do
|
341
|
+
@@memcache_client.should_not_receive(:delete)
|
342
|
+
@worker.send(:cleanup)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
294
346
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark-politics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Perham
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2010-01-05 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- README.rdoc
|
68
68
|
has_rdoc: true
|
69
69
|
homepage: http://github.com/infopark/politics
|
70
|
+
licenses: []
|
71
|
+
|
70
72
|
post_install_message:
|
71
73
|
rdoc_options:
|
72
74
|
- --charset=UTF-8
|
@@ -87,9 +89,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
89
|
requirements: []
|
88
90
|
|
89
91
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 1.3.5
|
91
93
|
signing_key:
|
92
|
-
specification_version:
|
94
|
+
specification_version: 3
|
93
95
|
summary: Algorithms and Tools for Distributed Computing in Ruby.
|
94
96
|
test_files:
|
95
97
|
- spec/static_queue_worker_spec.rb
|