Class: Testjour::CLI::Warm

Inherits:
BaseCommand show all
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 inherited from BaseCommand

detailed_help, help, #option_parser, options

Constructor Details

#initialize(*args) ⇒ Warm

Returns a new instance of Warm.



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

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

Class Method Details

.commandObject



10
11
12
# File 'lib/testjour/commands/warm.rb', line 10

def self.command
  "warm"
end

Instance Method Details

#available_serversObject



35
36
37
# File 'lib/testjour/commands/warm.rb', line 35

def available_servers
  @available_servers ||= Testjour::Bonjour.list
end


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

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



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

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



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

def run
  if available_servers.any?
    available_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



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

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