Class: Cangrejo::Support::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/cangrejo/support/launcher.rb

Defined Under Namespace

Classes: LaunchTimeout

Constant Summary collapse

SPAWN_TIMEOUT =
5
KILL_TIMEOUT =
5

Instance Method Summary collapse

Constructor Details

#initialize(_path, _options = {}) ⇒ Launcher

Returns a new instance of Launcher.



16
17
18
19
20
21
# File 'lib/cangrejo/support/launcher.rb', line 16

def initialize(_path, _options={})
  @path = _path
  @timeout = _options.fetch(:timeout, SPAWN_TIMEOUT)
  @argv = _options.fetch(:argv, [])
  select_socket_file
end

Instance Method Details

#hostObject



23
24
25
# File 'lib/cangrejo/support/launcher.rb', line 23

def host
  "unix://#{@socket_file}"
end

#killObject



34
35
36
# File 'lib/cangrejo/support/launcher.rb', line 34

def kill
  safe_kill @pid unless @pid.nil?
end

#launchObject



27
28
29
30
31
32
# File 'lib/cangrejo/support/launcher.rb', line 27

def launch
  gem_path = File.join(@path, 'Gemfile')
  # TODO: for some reason, the gemfile path must be specified here, maybe because of rbenv?
  @pid = Process.spawn({ 'BUNDLE_GEMFILE' => gem_path }, "bin/crabfarm s --host=#{host} #{@argv.join(' ')}", chdir: @path, pgroup: true)
  wait_for_socket
end