Class: Testbot::Runner::Job

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

Constant Summary collapse

TIME_TO_WAIT_BETWEEN_POSTING_RESULTS =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, id, build_id, project, root, type, ruby_interpreter, files) ⇒ Job

Returns a new instance of Job.



11
12
13
14
15
# File 'lib/runner/job.rb', line 11

def initialize(runner, id, build_id, project, root, type, ruby_interpreter, files)
  @runner, @id, @build_id, @project, @root, @type, @ruby_interpreter, @files =
    runner, id, build_id, project, root, type, ruby_interpreter, files
  @success = true
end

Instance Attribute Details

#build_idObject (readonly)

Returns the value of attribute build_id.



7
8
9
# File 'lib/runner/job.rb', line 7

def build_id
  @build_id
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'lib/runner/job.rb', line 7

def project
  @project
end

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/runner/job.rb', line 7

def root
  @root
end

Instance Method Details

#jruby?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/runner/job.rb', line 17

def jruby?
  @ruby_interpreter == 'jruby'
end

#kill!(build_id) ⇒ Object



37
38
39
40
41
42
# File 'lib/runner/job.rb', line 37

def kill!(build_id)
  if @build_id == build_id && @pid
    kill_processes
    @killed = true
  end
end

#run(instance) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/runner/job.rb', line 21

def run(instance)
  return if @killed
  puts "Running job #{@id} (build #{@build_id})... "
  test_env_number = (instance == 0) ? '' : instance + 1
  result = "\n#{`hostname`.chomp}:#{Dir.pwd}\n"
  base_environment = "export RAILS_ENV=test; export TEST_ENV_NUMBER=#{test_env_number}; cd #{@project};"

  adapter = Adapter.find(@type)
  run_time = measure_run_time do
    result += run_and_return_result("#{base_environment} #{adapter.command(@project, ruby_cmd, @files)}")
  end

  Server.put("/jobs/#{@id}", :body => { :result => SafeResultText.clean(result), :status => status, :time => run_time })
  puts "Job #{@id} finished."
end