Class: Bidi2pdf::ChromedriverManager
- Inherits:
-
Object
- Object
- Bidi2pdf::ChromedriverManager
- Includes:
- Chromedriver::Binary::Platform
- Defined in:
- lib/bidi2pdf/chromedriver_manager.rb
Instance Attribute Summary collapse
-
#chrome_args ⇒ Object
readonly
Returns the value of attribute chrome_args.
-
#headless ⇒ Object
readonly
Returns the value of attribute headless.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#reader_thread ⇒ Object
Returns the value of attribute reader_thread.
-
#shutdown_mutex ⇒ Object
readonly
Returns the value of attribute shutdown_mutex.
-
#started ⇒ Object
readonly
Returns the value of attribute started.
Instance Method Summary collapse
-
#initialize(port: 0, headless: true, chrome_args: Bidi::Session::DEFAULT_CHROME_ARGS) ⇒ ChromedriverManager
constructor
A new instance of ChromedriverManager.
- #session ⇒ Object
- #session_url ⇒ Object
- #start ⇒ Object
-
#stop(timeout: 5) ⇒ Object
rubocop: disable Metrics/AbcSize.
Constructor Details
#initialize(port: 0, headless: true, chrome_args: Bidi::Session::DEFAULT_CHROME_ARGS) ⇒ ChromedriverManager
Returns a new instance of ChromedriverManager.
13 14 15 16 17 18 19 20 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 13 def initialize(port: 0, headless: true, chrome_args: Bidi::Session::DEFAULT_CHROME_ARGS) @port = port @headless = headless @session = nil @started = false @chrome_args = chrome_args @shutdown_mutex ||= Mutex.new end |
Instance Attribute Details
#chrome_args ⇒ Object (readonly)
Returns the value of attribute chrome_args.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def chrome_args @chrome_args end |
#headless ⇒ Object (readonly)
Returns the value of attribute headless.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def headless @headless end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def port @port end |
#reader_thread ⇒ Object
Returns the value of attribute reader_thread.
11 12 13 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 11 def reader_thread @reader_thread end |
#shutdown_mutex ⇒ Object (readonly)
Returns the value of attribute shutdown_mutex.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def shutdown_mutex @shutdown_mutex end |
#started ⇒ Object (readonly)
Returns the value of attribute started.
10 11 12 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 10 def started @started end |
Instance Method Details
#session ⇒ Object
41 42 43 44 45 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 41 def session return unless @started @session ||= Bidi::Session.new(session_url: session_url, headless: @headless, chrome_args: @chrome_args) end |
#session_url ⇒ Object
47 48 49 50 51 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 47 def session_url return unless @started "http://localhost:#{@port}/session" end |
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 22 def start return @pid if @pid @started = true update_chromedriver cmd = build_cmd Bidi2pdf.logger.info "Starting Chromedriver with command: #{cmd}" spawn_process(cmd) Bidi2pdf.logger.info "Started Chromedriver on port #{@port}, PID #{@pid}" wait_until_chromedriver_ready at_exit { stop } @pid end |
#stop(timeout: 5) ⇒ Object
rubocop: disable Metrics/AbcSize
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bidi2pdf/chromedriver_manager.rb', line 54 def stop(timeout: 5) shutdown_mutex.synchronize do return unless @pid if reader_thread&.alive? begin reader_thread.kill reader_thread.join rescue StandardError => e Bidi2pdf.logger.error "Error killing reader thread: #{e.}" end end @started = false close_session debug_show_all_children old_childprocesses = term_chromedriver detect_zombie_processes old_childprocesses return unless process_alive? kill_chromedriver timeout: timeout ensure @pid = nil @started = false end end |