Class: GrpcServer::Engine
- Inherits:
-
Object
- Object
- GrpcServer::Engine
- Defined in:
- lib/grpc_server/engine.rb
Constant Summary collapse
- DEFAULT_HOST =
"0.0.0.0"
- DEFAULT_PORT =
50051
- DEFAULT_THREADS =
30
- DEFAULT_ENV =
"unknown"
- DEFAULT_GRACEFUL_SHUTDOWN_SIGNALS =
[ "TERM", "INT", ].freeze
Instance Method Summary collapse
-
#initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, threads: DEFAULT_THREADS, env: DEFAULT_ENV, interceptors: [], signals: DEFAULT_GRACEFUL_SHUTDOWN_SIGNALS, logger: nil) ⇒ Engine
constructor
A new instance of Engine.
- #run ⇒ Object
- #set_handler(service) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, threads: DEFAULT_THREADS, env: DEFAULT_ENV, interceptors: [], signals: DEFAULT_GRACEFUL_SHUTDOWN_SIGNALS, logger: nil) ⇒ Engine
Returns a new instance of Engine.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/grpc_server/engine.rb', line 28 def initialize(host: DEFAULT_HOST, port: DEFAULT_PORT, threads: DEFAULT_THREADS, env: DEFAULT_ENV, interceptors: [], signals: DEFAULT_GRACEFUL_SHUTDOWN_SIGNALS, logger: nil) @host = host @port = port @threads = threads @env = env @logger = logger || Logger.new($stdout) @signals = signals @server = GRPC::RpcServer.new( pool_size: @threads, interceptors: interceptors, ) @server.add_http2_port("#{@host}:#{@port}", :this_port_is_insecure) # Setup Health Cheker. # cf. https://github.com/grpc/grpc/blob/master/doc/health-checking.md @server.handle(health_checker) register_service_to_health_checker!(service: "") end |
Instance Method Details
#run ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/grpc_server/engine.rb', line 60 def run @logger.info("gRPC server starting...") @logger.info("* Max threads: #{@threads}") @logger.info("* Environment: #{@env}") @logger.info("* Listening on tcp://#{@host}:#{@port}") @logger.info("Use Ctrl-C to stop") @server.run_till_terminated_or_interrupted(@signals) @logger.info("Exiting") end |
#set_handler(service) ⇒ Object
55 56 57 58 |
# File 'lib/grpc_server/engine.rb', line 55 def set_handler(service) @server.handle(service) register_service_to_health_checker!(service: service.service_name) end |
#stop ⇒ Object
70 71 72 |
# File 'lib/grpc_server/engine.rb', line 70 def stop @server.stop end |