Class: Testjour::CLI::Warm

Inherits:
BaseCommand show all
Includes:
Bonjour
Defined in:
lib/testjour/commands/warm.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#non_options, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bonjour

#bonjour_serve, #bonjour_servers, #found_bonjour_server

Methods inherited from BaseCommand

detailed_help, help, inherited, #option_parser, options

Constructor Details

#initialize(*args) ⇒ Warm

Returns a new instance of Warm.



16
17
18
19
20
21
22
# File 'lib/testjour/commands/warm.rb', line 16

def initialize(*args)
  Testjour.logger.debug "Runner command #{self.class}..."
  
  super
  @found_server = 0
  require "testjour/colorer"
end

Class Method Details

.commandObject



12
13
14
# File 'lib/testjour/commands/warm.rb', line 12

def self.command
  "warm"
end

Instance Method Details



49
50
51
52
53
54
55
56
57
# File 'lib/testjour/commands/warm.rb', line 49

def print_results
  if @found_server > 0
    puts
    puts "#{@found_server} slave accepted the warm request."
  else
    puts
    puts Testjour::Colorer.failed("Found available servers, but none accepted the warm request. Try again later.")
  end
end

#request_warm_from(server) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/testjour/commands/warm.rb', line 37

def request_warm_from(server)
  slave_server = DRbObject.new(nil, server.uri)
  result = slave_server.warm(testjour_uri)
  
  if result
    Testjour.logger.info "Requesting warm from available server: #{server.uri}. Accepted."
    @found_server += 1
  else
    Testjour.logger.info "Requesting warm from available server: #{server.uri}. Rejected."
  end
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/testjour/commands/warm.rb', line 24

def run
  if bonjour_servers.any?
    bonjour_servers.each do |server|
      request_warm_from(server)
    end
    
    print_results
  else
    puts
    puts Testjour::Colorer.failed("Don't see any available test servers. Try again later.")
  end
end

#testjour_uriObject



59
60
61
62
63
64
65
66
# File 'lib/testjour/commands/warm.rb', line 59

def testjour_uri
  DRb.start_service
  uri = URI.parse(DRb.uri)
  uri.path = File.expand_path(".")
  uri.scheme = "testjour"
  uri.user = `whoami`.strip
  uri.to_s
end