Class: DeepTest::ProcessOrchestrator

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, workers, runner) ⇒ ProcessOrchestrator

Returns a new instance of ProcessOrchestrator.



7
8
9
10
11
# File 'lib/deep_test/process_orchestrator.rb', line 7

def initialize(options, workers, runner)
  @options = options
  @runner = runner
  @workers = workers
end

Class Method Details

.run(options, workers, runner) ⇒ Object



3
4
5
# File 'lib/deep_test/process_orchestrator.rb', line 3

def self.run(options, workers, runner)
  new(options, workers, runner).run
end

Instance Method Details

#run(exit_when_done = true) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deep_test/process_orchestrator.rb', line 13

def run(exit_when_done = true)
  passed = false

  begin
    server = Server.start(@options)
    @options.new_listener_list.before_starting_workers
    @workers.start_all(server)
    begin
      DeepTest.logger.debug "Loader Starting (#{$$})"
      passed = @runner.process_work_units(server)
    ensure
      shutdown(server)
    end
  ensure
    DeepTest.logger.debug "ProcessOrchestrator: Stopping Server"
    Server.stop
  end

  Kernel.exit(passed ? 0 : 1) if exit_when_done
end

#shutdown(server) ⇒ Object



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

def shutdown(server)
  DeepTest.logger.debug "ProcessOrchestrator: Shutting Down"
  server.done_with_work

  first_exception = $!
  begin
    DeepTest.logger.debug "ProcessOrchestrator: Stopping Workers"
    @workers.stop_all
  rescue DRb::DRbConnError
    # Workers must have already stopped
  rescue Exception => e
    raise first_exception || e
  end
end