Class: GoodJob::ProbeServer::SimpleHandler
- Inherits:
-
Object
- Object
- GoodJob::ProbeServer::SimpleHandler
- Defined in:
- lib/good_job/probe_server/simple_handler.rb
Constant Summary collapse
- SOCKET_READ_TIMEOUT =
in seconds
5- CLIENT_READ_TIMEOUT =
in seconds
1- MAX_REQUEST_LINE_LENGTH =
in bytes
8192
Instance Method Summary collapse
- #build_future ⇒ Object
-
#close_socket ⇒ Object
Closes this process's copy of the socket, for a process that inherited it across a fork.
-
#initialize(app, options = {}) ⇒ SimpleHandler
constructor
A new instance of SimpleHandler.
-
#listen ⇒ Object
Binds the listening socket, before the thread that serves it is started, so that a process forking afterwards can reliably close its inherited copy.
- #running? ⇒ Boolean
- #stop ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ SimpleHandler
Returns a new instance of SimpleHandler.
14 15 16 17 18 19 20 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 14 def initialize(app, = {}) @app = app @port = [:port] @logger = [:logger] @running = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#build_future ⇒ Object
45 46 47 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 45 def build_future Concurrent::Future.new { run } end |
#close_socket ⇒ Object
Closes this process's copy of the socket, for a process that inherited it across a fork.
28 29 30 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 28 def close_socket @server&.close end |
#listen ⇒ Object
Binds the listening socket, before the thread that serves it is started, so that a process forking afterwards can reliably close its inherited copy.
38 39 40 41 42 43 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 38 def listen @server = TCPServer.new('0.0.0.0', @port) @running.make_true rescue StandardError => e @logger.error "Failed to start server: #{e}" end |
#running? ⇒ Boolean
32 33 34 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 32 def running? @running.true? end |
#stop ⇒ Object
22 23 24 25 |
# File 'lib/good_job/probe_server/simple_handler.rb', line 22 def stop @running.make_false @server&.close end |