Module: Conspire
- Defined in:
- lib/conspire.rb,
lib/conspire/conspirator.rb
Defined Under Namespace
Classes: Conspirator
Constant Summary collapse
- VERSION =
'0.0.1'- DEFAULTS =
{ :port => 7456, :name => 'conspiracy', :sync_interval => 0.5 }
- HOSTNAME =
`hostname`.chomp
Class Method Summary collapse
- .conspirators ⇒ Object
-
.discover(wait = 5) ⇒ Object
This should be called periodically.
- .discover_loop ⇒ Object
-
.start(path, options) ⇒ Object
Begin a conspiracy session.
- .sync_all ⇒ Object
- .sync_loop ⇒ Object
Class Method Details
.conspirators ⇒ Object
65 |
# File 'lib/conspire.rb', line 65 def conspirators; @conspirators end |
.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 == .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
58 59 60 61 62 63 |
# File 'lib/conspire.rb', line 58 def discover_loop loop do Conspire.discover p Conspire.conspirators if ENV['DEBUG'] end 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 = path puts "Starting with #{@options.inspect}" if ENV['DEBUG'] Gitjour::Application.init @path @thread = Thread.new do Gitjour::Application.serve(@path, .name, .port) end end |
.sync_all ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/conspire.rb', line 43 def sync_all @conspirators.map do |c| begin c.sync(@path) rescue => e puts "Dropping #{c} because #{e.message}" @conspirators.delete c end end end |
.sync_loop ⇒ Object
54 55 56 |
# File 'lib/conspire.rb', line 54 def sync_loop loop { sync_all and sleep .sync_interval } end |