Class: GoodJob::ProbeServer
- Inherits:
-
Object
- Object
- GoodJob::ProbeServer
- 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,
lib/good_job/probe_server/cluster_healthcheck_middleware.rb
Defined Under Namespace
Modules: NotFoundApp Classes: ClusterHealthcheckMiddleware, HealthcheckMiddleware, SimpleHandler, WebrickHandler
Class Method Summary collapse
-
.cluster_app(supervisor) ⇒ #call
Rack app for a supervisor in cluster mode; reports cluster-wide health instead of the current process's (empty) scheduler/notifier state.
- .default_app ⇒ Object
-
.task_observer(time, output, thread_error) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Instance Method Summary collapse
- #build_handler(port:, handler:, app:) ⇒ Object
-
#close_socket ⇒ Object
Closes this process's copy of the listening socket without stopping the server, for a process that inherited it across a
fork(see Supervisor). -
#initialize(port:, handler: nil, app: nil) ⇒ ProbeServer
constructor
A new instance of ProbeServer.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port:, handler: nil, app: nil) ⇒ ProbeServer
Returns a new instance of ProbeServer.
32 33 34 35 |
# File 'lib/good_job/probe_server.rb', line 32 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
.cluster_app(supervisor) ⇒ #call
Rack app for a supervisor in cluster mode; reports cluster-wide health instead of the current process's (empty) scheduler/notifier state.
25 26 27 28 29 30 |
# File 'lib/good_job/probe_server.rb', line 25 def self.cluster_app(supervisor) ::Rack::Builder.new do use GoodJob::ProbeServer::ClusterHealthcheckMiddleware, supervisor run GoodJob::ProbeServer::NotFoundApp end end |
.default_app ⇒ Object
14 15 16 17 18 19 |
# File 'lib/good_job/probe_server.rb', line 14 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
8 9 10 11 12 |
# File 'lib/good_job/probe_server.rb', line 8 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/good_job/probe_server.rb', line 59 def build_handler(port:, handler:, app:) case handler when :webrick begin require 'webrick' WebrickHandler.new(app, port: port, logger: GoodJob.logger) rescue LoadError GoodJob.deprecator.warn(<<~MSG) `probe_handler: :webrick` is specified but WEBrick is not in the load path, so GoodJob's own webserver is used instead. Add `gem "webrick"` to your Gemfile. This fallback is deprecated and will raise in the next release. MSG SimpleHandler.new(app, port: port, logger: GoodJob.logger) end when nil SimpleHandler.new(app, port: port, logger: GoodJob.logger) else GoodJob.deprecator.warn(<<~MSG) `probe_handler: #{handler.inspect}` is not supported, so GoodJob's own webserver is used instead. Specify `:webrick` or `nil`. This fallback is deprecated and will raise in the next release. MSG SimpleHandler.new(app, port: port, logger: GoodJob.logger) end end |
#close_socket ⇒ Object
Closes this process's copy of the listening socket without stopping the server,
for a process that inherited it across a fork (see Supervisor).
55 56 57 |
# File 'lib/good_job/probe_server.rb', line 55 def close_socket @handler&.close_socket end |
#running? ⇒ Boolean
44 45 46 |
# File 'lib/good_job/probe_server.rb', line 44 def running? @handler&.running? end |
#start ⇒ Object
37 38 39 40 41 42 |
# File 'lib/good_job/probe_server.rb', line 37 def start @handler.listen @future = @handler.build_future @future.add_observer(self.class, :task_observer) @future.execute end |
#stop ⇒ Object
48 49 50 51 |
# File 'lib/good_job/probe_server.rb', line 48 def stop @handler&.stop @future&.value # wait for Future to exit end |