Class: Crabfarm::PhantomRunner
- Inherits:
-
Object
- Object
- Crabfarm::PhantomRunner
- Defined in:
- lib/crabfarm/phantom_runner.rb
Constant Summary collapse
- PHANTOM_START_TM =
seconds
5
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(_config = {}) ⇒ PhantomRunner
constructor
A new instance of PhantomRunner.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(_config = {}) ⇒ PhantomRunner
Returns a new instance of PhantomRunner.
11 12 13 14 |
# File 'lib/crabfarm/phantom_runner.rb', line 11 def initialize(_config={}) @config = _config; @pid = nil end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/crabfarm/phantom_runner.rb', line 9 def port @port end |
Instance Method Details
#start ⇒ Object
16 17 18 19 20 21 |
# File 'lib/crabfarm/phantom_runner.rb', line 16 def start find_available_port Crabfarm.logger.info "Starting phantomjs in port #{@port}" @pid = spawn_phantomjs Crabfarm.logger.info "Phantomjs started (PID: #{@pid})" end |
#stop ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/crabfarm/phantom_runner.rb', line 23 def stop unless @pid.nil? Crabfarm.logger.info "Stopping phantomjs (PID: #{@pid})" Process.kill "INT", @pid Process.wait @pid, Process::WNOHANG Crabfarm.logger.info "Phantomjs stopped (PID: #{@pid})" @pid = nil end end |