Class: AnyCable::HealthServer
- Inherits:
-
Object
- Object
- AnyCable::HealthServer
- Defined in:
- lib/anycable/health_server.rb
Overview
Constant Summary collapse
- SUCCESS_RESPONSE =
[200, "Ready"].freeze
- FAILURE_RESPONSE =
[503, "Not Ready"].freeze
Instance Attribute Summary collapse
-
#http_server ⇒ Object
readonly
Returns the value of attribute http_server.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(server, port:, logger: nil, path: "/health") ⇒ HealthServer
constructor
A new instance of HealthServer.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(server, port:, logger: nil, path: "/health") ⇒ HealthServer
Returns a new instance of HealthServer.
23 24 25 26 27 28 29 |
# File 'lib/anycable/health_server.rb', line 23 def initialize(server, port:, logger: nil, path: "/health") @server = server @port = port @path = path @logger = logger @http_server = build_server end |
Instance Attribute Details
#http_server ⇒ Object (readonly)
Returns the value of attribute http_server.
21 22 23 |
# File 'lib/anycable/health_server.rb', line 21 def http_server @http_server end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/anycable/health_server.rb', line 21 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
21 22 23 |
# File 'lib/anycable/health_server.rb', line 21 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
21 22 23 |
# File 'lib/anycable/health_server.rb', line 21 def server @server end |
Instance Method Details
#running? ⇒ Boolean
45 46 47 |
# File 'lib/anycable/health_server.rb', line 45 def running? http_server.status == :Running end |
#start ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/anycable/health_server.rb', line 31 def start return if running? Thread.new { http_server.start } logger.info "HTTP health server is listening on localhost:#{port} and mounted at \"#{path}\"" end |
#stop ⇒ Object
39 40 41 42 43 |
# File 'lib/anycable/health_server.rb', line 39 def stop return unless running? http_server.shutdown end |