Class: GoodJob::ProbeServer::WebrickHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/good_job/probe_server/webrick_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ WebrickHandler

Returns a new instance of WebrickHandler.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/good_job/probe_server/webrick_handler.rb', line 6

def initialize(app, options = {})
  @app    = app
  @port   = options[:port]
  @logger = options[:logger]

  # Workaround for rack >= 3.1.x as auto-loading of rack/handler was removed.
  # We should move to rackup in the long run.
  # See https://github.com/rack/rack/pull/1937.
  @handler = begin
    require 'rackup/handler'
    ::Rackup::Handler.get('webrick')
  rescue LoadError
    require "rack/handler"
    ::Rack::Handler.get('webrick')
  end
end

Instance Method Details

#build_futureObject



31
32
33
34
35
# File 'lib/good_job/probe_server/webrick_handler.rb', line 31

def build_future
  Concurrent::Future.new(args: [@handler, @port, GoodJob.logger]) do |thr_handler, thr_port, thr_logger|
    thr_handler.run(@app, Port: thr_port, Host: '0.0.0.0', Logger: thr_logger, AccessLog: [])
  end
end

#running?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/good_job/probe_server/webrick_handler.rb', line 27

def running?
  @handler&.instance_variable_get(:@server)&.status == :Running
end

#stopObject



23
24
25
# File 'lib/good_job/probe_server/webrick_handler.rb', line 23

def stop
  @handler&.shutdown
end