Class: Crabfarm::Support::PhantomRunner

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

Constant Summary collapse

PHANTOM_START_TM =

seconds

5

Instance Method Summary collapse

Constructor Details

#initialize(_config = {}) ⇒ PhantomRunner

Returns a new instance of PhantomRunner.



11
12
13
14
# File 'lib/crabfarm/support/phantom_runner.rb', line 11

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

Instance Method Details

#portObject



16
17
18
# File 'lib/crabfarm/support/phantom_runner.rb', line 16

def port
  @config[:port]
end

#startObject



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

def start
  logger.info "Starting phantomjs in port #{port}"
  @process = spawn_phantomjs
  logger.info "Phantomjs started (PID: #{@process.pid})"
end

#stopObject



26
27
28
29
30
31
32
33
# File 'lib/crabfarm/support/phantom_runner.rb', line 26

def stop
  unless @process.nil?
    logger.info "Stopping phantomjs (PID: #{@process.pid})"
    @process.stop
    @process = nil
    logger.info "Phantomjs stopped"
  end
end