Class: GoodJob::ProbeServer

Inherits:
Object
  • Object
show all
Defined in:
lib/good_job/probe_server.rb,
lib/good_job/probe_server/not_found_app.rb,
lib/good_job/probe_server/simple_handler.rb,
lib/good_job/probe_server/webrick_handler.rb,
lib/good_job/probe_server/healthcheck_middleware.rb

Defined Under Namespace

Modules: NotFoundApp Classes: HealthcheckMiddleware, SimpleHandler, WebrickHandler

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port:, handler: nil, app: nil) ⇒ ProbeServer

Returns a new instance of ProbeServer.



18
19
20
21
# File 'lib/good_job/probe_server.rb', line 18

def initialize(port:, handler: nil, app: nil)
  app ||= self.class.default_app
  @handler = build_handler(port: port, handler: handler, app: app)
end

Class Method Details

.default_appObject



11
12
13
14
15
16
# File 'lib/good_job/probe_server.rb', line 11

def self.default_app
  ::Rack::Builder.new do
    use GoodJob::ProbeServer::HealthcheckMiddleware
    run GoodJob::ProbeServer::NotFoundApp
  end
end

.task_observer(time, output, thread_error) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



5
6
7
8
9
# File 'lib/good_job/probe_server.rb', line 5

def self.task_observer(time, output, thread_error) # rubocop:disable Lint/UnusedMethodArgument
  return if thread_error.is_a? Concurrent::CancelledOperationError

  GoodJob._on_thread_error(thread_error) if thread_error
end

Instance Method Details

#build_handler(port:, handler:, app:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/good_job/probe_server.rb', line 38

def build_handler(port:, handler:, app:)
  if handler == :webrick
    begin
      require 'webrick'
      WebrickHandler.new(app, port: port, logger: GoodJob.logger)
    rescue LoadError
      GoodJob.logger.warn("WEBrick was requested as the probe server handler, but it's not in the load path. GoodJob doesn't keep WEBrick as a dependency, so you'll have to make sure its added to your Gemfile to make use of it. GoodJob will fallback to its own webserver in the meantime.")
      SimpleHandler.new(app, port: port, logger: GoodJob.logger)
    end
  else
    SimpleHandler.new(app, port: port, logger: GoodJob.logger)
  end
end

#running?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/good_job/probe_server.rb', line 29

def running?
  @handler&.running?
end

#startObject



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

def start
  @future = @handler.build_future
  @future.add_observer(self.class, :task_observer)
  @future.execute
end

#stopObject



33
34
35
36
# File 'lib/good_job/probe_server.rb', line 33

def stop
  @handler&.stop
  @future&.value # wait for Future to exit
end