Class: Crabfarm::PhantomRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/phantom_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_config = {}) ⇒ PhantomRunner

Returns a new instance of PhantomRunner.



8
9
10
11
# File 'lib/crabfarm/phantom_runner.rb', line 8

def initialize(_config={})
  @config = _config;
  @pid = nil
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/crabfarm/phantom_runner.rb', line 6

def port
  @port
end

Instance Method Details

#startObject



13
14
15
16
17
# File 'lib/crabfarm/phantom_runner.rb', line 13

def start
  find_available_port
  @pid = Process.spawn({}, phantomjs_cmd)
  wait_for_server
end

#stopObject



19
20
21
22
23
24
25
# File 'lib/crabfarm/phantom_runner.rb', line 19

def stop
  unless @pid.nil?
    Process.kill("TERM", @pid)
    Process.wait @pid
    @pid = nil
  end
end