mperham-politics 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,6 +1,11 @@
1
1
  = Changelog
2
2
 
3
- == 0.2.0 (2008-10-??)
3
+ == 0.2.1 (2008-11-04)
4
+
5
+ * Cleanup and prepare for public release for RubyConf 2008.
6
+ * Election Day. Politics. Get it? Hee hee.
7
+
8
+ == 0.2.0 (2008-10-24)
4
9
 
5
10
  * Remove BucketWorker based on initial feedback. Add StaticQueueWorker as a more reliable replacement.
6
11
 
data/README.rdoc CHANGED
@@ -21,7 +21,7 @@ toes? There are several answers:
21
21
  1. Elect a leader for a short period of time. The leader is the process which performs the
22
22
  actual processing. After a length of time, a new leader is elected from the group. This
23
23
  is fault tolerant but not as scalable, as only one process is performing the task at a given
24
- point in time. See the +TokenWorker+ and +PaxosMember+ mixins.
24
+ point in time. See the +TokenWorker+ mixin.
25
25
 
26
26
  == Dependencies
27
27
 
@@ -39,6 +39,7 @@ TokenWorker mixin
39
39
  Name:: Mike Perham
40
40
  Email:: mailto:mperham@gmail.com
41
41
  Twitter:: http://twitter.com/mperham
42
+ Homepage:: http://mikeperham.com/politics/
42
43
 
43
44
  This software is free for you to use as you'd like. If you find it useful, please consider giving
44
45
  me a recommendation at {Working with Rails}[http://workingwithrails.com/person/10797-mike-perham].
@@ -0,0 +1,37 @@
1
+ #gem 'mperham-politics'
2
+ require 'politics'
3
+ require 'politics/static_queue_worker'
4
+
5
+ # Test this example by starting memcached locally and then in two irb sessions, run this:
6
+ #
7
+ =begin
8
+ require 'queue_worker_example'
9
+ p = Politics::QueueWorkerExample.new
10
+ p.start
11
+ =end
12
+ #
13
+ # You can then watch as one of them is elected leader. You can kill the leader and verify
14
+ # the backup process is elected after approximately iteration_length seconds.
15
+ #
16
+ module Politics
17
+ class QueueWorkerExample
18
+ include Politics::StaticQueueWorker
19
+ TOTAL_BUCKETS = 20
20
+
21
+ def initialize
22
+ register_worker 'queue-example', TOTAL_BUCKETS, :iteration_length => 60, :servers => memcached_servers
23
+ end
24
+
25
+ def start
26
+ process_bucket do |bucket|
27
+ puts "PID #{$$} processing bucket #{bucket}/#{TOTAL_BUCKETS} at #{Time.now}..."
28
+ sleep 1.5
29
+ end
30
+ end
31
+
32
+ def memcached_servers
33
+ ['127.0.0.1:11211']
34
+ end
35
+
36
+ end
37
+ end
@@ -4,15 +4,15 @@ require 'politics/token_worker'
4
4
 
5
5
  # Test this example by starting memcached locally and then in two irb sessions, run this:
6
6
  #
7
- #
8
- # You can then watch as one of them is elected leader. You can kill the leader and verify
9
- # the backup process is elected after approximately iteration_length seconds.
10
- #
11
7
  =begin
12
8
  require 'token_worker_example'
13
9
  p = Politics::TokenWorkerExample.new
14
10
  p.start
15
11
  =end
12
+ #
13
+ # You can then watch as one of them is elected leader. You can kill the leader and verify
14
+ # the backup process is elected after approximately iteration_length seconds.
15
+ #
16
16
  module Politics
17
17
  class TokenWorkerExample
18
18
  include Politics::TokenWorker
@@ -1,4 +1,3 @@
1
- puts 'hello'
2
1
  require 'socket'
3
2
  require 'ipaddr'
4
3
  require 'uri'
@@ -235,12 +234,12 @@ module Politics
235
234
  handle = Net::DNS::MDNSSD.register("#{self.group_name}-#{local_ip}-#{$$}",
236
235
  "_#{group_name}._tcp", 'local', @port)
237
236
 
238
- ['INT', 'TERM'].each { |signal|
239
- trap(signal) do
240
- handle.stop
241
- server.stop_service
242
- end
243
- }
237
+ # ['INT', 'TERM'].each { |signal|
238
+ # trap(signal) do
239
+ # handle.stop
240
+ # server.stop_service
241
+ # end
242
+ # }
244
243
  end
245
244
 
246
245
  def bonjour_scan
@@ -1,5 +1,5 @@
1
1
  module Politics
2
2
  module Version
3
- STRING = "0.2.0"
3
+ STRING = "0.2.1"
4
4
  end
5
5
  end
data/lib/politics.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'logger'
2
-
3
1
  module Politics
4
2
 
5
3
  def self.log=(value)
@@ -7,6 +5,11 @@ module Politics
7
5
  end
8
6
 
9
7
  def self.log
10
- @log ||= Logger.new(STDOUT)
8
+ @log ||= if defined?(RAILS_DEFAULT_LOGGER)
9
+ RAILS_DEFAULT_LOGGER
10
+ else
11
+ require 'logger'
12
+ Logger.new(STDOUT)
13
+ end
11
14
  end
12
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mperham-politics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham