Class: DTR::Agent::Runner

Inherits:
Object show all
Includes:
DRbUndumped, Service::Runner
Defined in:
lib/dtr/agent/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Service::Runner

#lookup_runner, #provide_runner

Methods included from Service::Rinda

#lookup, #lookup_ring, #start_service, #stop_service

Constructor Details

#initialize(name, env) ⇒ Runner

Returns a new instance of Runner.



28
29
30
31
32
# File 'lib/dtr/agent/runner.rb', line 28

def initialize(name, env)
  @name = name
  @identifier = env[:identifier]
  @env = env
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



26
27
28
# File 'lib/dtr/agent/runner.rb', line 26

def identifier
  @identifier
end

#nameObject (readonly)

Returns the value of attribute name.



26
27
28
# File 'lib/dtr/agent/runner.rb', line 26

def name
  @name
end

Class Method Details

.start(name, env) ⇒ Object



21
22
23
24
# File 'lib/dtr/agent/runner.rb', line 21

def self.start(name, env)
  self.new(name, env).start
  DRb.thread.join if DRb.thread
end

Instance Method Details

#init_environmentObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dtr/agent/runner.rb', line 46

def init_environment
  DTR.info {"#{name}: Initialize working environment..."}
  ENV['DTR_RUNNER_NAME'] = name

  @env[:libs].select{ |lib| !$LOAD_PATH.include?(lib) && File.exists?(lib) }.each do |lib|
    $LOAD_PATH << lib
    DTR.debug {"#{name}: appended lib: #{lib}"}
  end
  DTR.info {"#{name}: libs loaded"}
  DTR.debug {"#{name}: $LOAD_PATH: #{$LOAD_PATH.inspect}"}

  @env[:files].each do |f|
    begin
      load f unless f =~ /^-/
      DTR.debug {"#{name}: loaded #{f}"}
    rescue LoadError => e
      DTR.error {"#{name}: No such file to load -- #{f}"}
      DTR.debug {"Environment: #{@env}"}
    end
  end
  DTR.info {"#{name}: test files loaded"}
end

#provideObject



78
79
80
# File 'lib/dtr/agent/runner.rb', line 78

def provide
  provide_runner(self)
end

#run(test, result, &progress_block) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/dtr/agent/runner.rb', line 69

def run(test, result, &progress_block)
  DTR.debug {"#{name}: running #{test}..."}
  Agent::TestCase.new(test, result, &progress_block).run
  DTR.debug {"#{name}: done #{test}"}
ensure
  provide
  DTR.debug {"=> Runner #{name} provided"}
end

#startObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dtr/agent/runner.rb', line 34

def start
  #start service first, so that all logs can be sync with master process
  start_service
  DTR.info("=> Starting runner #{name} at #{Dir.pwd}, pid: #{Process.pid}")
  init_environment
  provide
  DTR.info {"=> Runner #{name} provided"}
rescue Exception
  DTR.error($!.message)
  DTR.error($!.backtrace.join("\n"))
end

#to_sObject



82
83
84
# File 'lib/dtr/agent/runner.rb', line 82

def to_s
  "Runner #{@name}"
end