Class: Testbot::Runner::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/runner/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Runner

Returns a new instance of Runner.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/runner/runner.rb', line 34

def initialize(config)
  @instances = []
  @last_build_id = nil
  @last_version_check = Time.now - TIME_BETWEEN_VERSION_CHECKS - 1
  @config = OpenStruct.new(config)
  @config.max_instances = @config.max_instances ? @config.max_instances.to_i : CPU.count 

  if @config.ssh_tunnel
    server_uri = "http://127.0.0.1:#{Testbot::SERVER_PORT}"
  else
    server_uri = "http://#{@config.server_host}:#{Testbot::SERVER_PORT}"
  end

  Server.base_uri(server_uri)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



50
51
52
# File 'lib/runner/runner.rb', line 50

def config
  @config
end

Instance Method Details

#run!Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/runner/runner.rb', line 52

def run!
  # Remove legacy instance* and *_rsync|git style folders
  Dir.entries(".").find_all { |name| name.include?('instance') || name.include?('_rsync') ||
    name.include?('_git') }.each { |folder|
    system "rm -rf #{folder}"
  }

  SSHTunnel.new(@config.server_host, @config.server_user || Testbot::DEFAULT_USER).open if @config.ssh_tunnel
  while true
    begin
      update_uid!
      start_ping
      wait_for_jobs
    rescue Exception => ex
      break if [ 'SignalException', 'Interrupt' ].include?(ex.class.to_s)
      puts "The runner crashed, restarting. Error: #{ex.inspect} #{ex.class}"
    end
  end
end