Class: Megatest::Executor::ExternalMonitor

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ExternalMonitor

Returns a new instance of ExternalMonitor.



8
9
10
11
12
# File 'lib/megatest/executor.rb', line 8

def initialize(config)
  require "rbconfig"
  @config = config
  spawn
end

Instance Method Details

#reapObject



14
15
16
17
18
19
20
21
22
# File 'lib/megatest/executor.rb', line 14

def reap
  if @pipe
    @pipe.close
    @pipe = nil
    _, status = Process.waitpid2(@pid)
    @pid = nil
    status
  end
end

#spawnObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/megatest/executor.rb', line 24

def spawn
  child_read, @pipe = IO.pipe
  ready_pipe, child_write = IO.pipe
  @pid = Process.spawn(
    RbConfig.ruby,
    File.expand_path("../queue_monitor.rb", __FILE__),
    in: child_read,
    out: child_write,
  )
  child_read.close
  Marshal.dump(@config, @pipe)

  # Check the process is alive.
  if ready_pipe.wait_readable(10)
    ready_pipe.gets
    ready_pipe.close
    Process.kill(0, @pid)
  else
    Process.kill(0, @pid)
    Process.wait(@pid)
    raise Error, "ExternalMonitor failed to boot"
  end
end