Module: Conspire
- Defined in:
- lib/conspire.rb,
lib/conspire/conspirator.rb
Defined Under Namespace
Classes: Conspirator
Constant Summary collapse
- VERSION =
'0.1.2'
- DEFAULTS =
TODO: play with optimal intervals; perhaps auto-adjust based on latency?
{ :port => 7456, :name => 'conspiracy', :sync_interval => 0.25 }
- HOSTNAME =
TODO: is there a better way?
`hostname`.chomp
Class Method Summary collapse
-
.discover(wait = 5) ⇒ Object
This should be called periodically.
- .discover_loop ⇒ Object
-
.start(path, options) ⇒ Object
Begin a conspiracy session.
-
.sync_all ⇒ Object
Sync with all conspirators, dropping the problematic ones.
- .sync_loop ⇒ Object
Class Method Details
.discover(wait = 5) ⇒ Object
This should be called periodically
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/conspire.rb', line 32 def discover(wait = 5) Gitjour::Application.discover(wait) do |service| next if service.name !~ /conspiracy/ # TODO: better way of choosing names next if(service.port.to_i == @options.port.to_i and service.host.gsub(/\.local\.$/, '') == HOSTNAME) # No-op if we've got it already, since @conspirators is a Set @conspirators << Conspirator.new(service.host, service.port, service.name) end end |
.discover_loop ⇒ Object
59 60 61 |
# File 'lib/conspire.rb', line 59 def discover_loop loop { discover and (p @conspirators if ENV['DEBUG']) } end |
.start(path, options) ⇒ Object
Begin a conspiracy session
21 22 23 24 25 26 27 28 29 |
# File 'lib/conspire.rb', line 21 def start(path, ) @path, @options = path, Gitjour::Application.init @path @thread = Thread.new do Gitjour::Application.serve(@path, @options.name, @options.port) end end |
.sync_all ⇒ Object
Sync with all conspirators, dropping the problematic ones
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/conspire.rb', line 44 def sync_all @conspirators.map do |c| begin c.sync(@path) rescue => e puts "Dropping #{c} because #{e.}" @conspirators.delete c end end end |
.sync_loop ⇒ Object
55 56 57 |
# File 'lib/conspire.rb', line 55 def sync_loop loop { sync_all and sleep @options.sync_interval } end |