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

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_loopObject



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, options)
  @path, @options = path, options

  Gitjour::Application.init @path

  @thread = Thread.new do
    Gitjour::Application.serve(@path, @options.name, @options.port)
  end
end

.sync_allObject

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.message}"
      @conspirators.delete c
    end
  end
end

.sync_loopObject



55
56
57
# File 'lib/conspire.rb', line 55

def sync_loop
  loop { sync_all and sleep @options.sync_interval }
end