Class: Postdoc::ChromeProcess
- Inherits:
-
Object
- Object
- Postdoc::ChromeProcess
- Defined in:
- lib/postdoc/chrome_process.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #client ⇒ Object
-
#initialize(port: Random.rand(65_535 - 1024), **_options) ⇒ ChromeProcess
constructor
A new instance of ChromeProcess.
- #kill ⇒ Object
Constructor Details
#initialize(port: Random.rand(65_535 - 1024), **_options) ⇒ ChromeProcess
Returns a new instance of ChromeProcess.
7 8 9 10 11 |
# File 'lib/postdoc/chrome_process.rb', line 7 def initialize(port: Random.rand(65_535 - 1024), **) @port = port @pid = Process.spawn "chrome --remote-debugging-port=#{port} --headless", out: File::NULL, err: File::NULL end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/postdoc/chrome_process.rb', line 5 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/postdoc/chrome_process.rb', line 5 def port @port end |
Instance Method Details
#alive? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/postdoc/chrome_process.rb', line 13 def alive? @alive ||= test_socket! rescue Errno::ECONNREFUSED false end |
#client ⇒ Object
26 27 28 |
# File 'lib/postdoc/chrome_process.rb', line 26 def client Client.new port end |
#kill ⇒ Object
19 20 21 22 23 24 |
# File 'lib/postdoc/chrome_process.rb', line 19 def kill Process.kill 'INT', pid Process.wait pid rescue true end |