Class: AnyCable::HealthServer
- Inherits:
-
Object
- Object
- AnyCable::HealthServer
- Defined in:
- lib/anycable/health_server.rb
Overview
Server for HTTP healthchecks.
Basic usage:
# create a new healthcheck server for a specified
# gRPC server lisening on the port
health_server = AnyCable::HealthServer.new(grpc_server, port)
# start health server in background
health_server.start
# stop health server
health_server.stop
Constant Summary collapse
- SUCCESS_RESPONSE =
[200, "Ready"].freeze
- FAILURE_RESPONSE =
[503, "Not Ready"].freeze
Instance Attribute Summary collapse
-
#grpc_server ⇒ Object
readonly
Returns the value of attribute grpc_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(grpc_server, port:, path: "/health", logger: AnyCable.logger) ⇒ HealthServer
constructor
A new instance of HealthServer.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(grpc_server, port:, path: "/health", logger: AnyCable.logger) ⇒ HealthServer
Returns a new instance of HealthServer.
25 26 27 28 29 30 31 |
# File 'lib/anycable/health_server.rb', line 25 def initialize(grpc_server, port:, path: "/health", logger: AnyCable.logger) @grpc_server = grpc_server @port = port @path = path @logger = logger @server = build_server end |
Instance Attribute Details
#grpc_server ⇒ Object (readonly)
Returns the value of attribute grpc_server.
23 24 25 |
# File 'lib/anycable/health_server.rb', line 23 def grpc_server @grpc_server end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/anycable/health_server.rb', line 23 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
23 24 25 |
# File 'lib/anycable/health_server.rb', line 23 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
23 24 25 |
# File 'lib/anycable/health_server.rb', line 23 def server @server end |
Instance Method Details
#running? ⇒ Boolean
47 48 49 |
# File 'lib/anycable/health_server.rb', line 47 def running? server.status == :Running end |
#start ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/anycable/health_server.rb', line 33 def start return if running? Thread.new { server.start } logger.info "HTTP health server is listening on localhost:#{port} and mounted at \"#{path}\"" end |
#stop ⇒ Object
41 42 43 44 45 |
# File 'lib/anycable/health_server.rb', line 41 def stop return unless running? server.shutdown end |