Module: Grpcx::Server

Extended by:
ActiveSupport::Concern
Includes:
ActiveSupport::Rescuable
Defined in:
lib/grpcx/server.rb,
lib/grpcx/server/interceptors/rescue.rb,
lib/grpcx/server/interceptors/active_record.rb,
lib/grpcx/server/interceptors/instrumentation.rb

Defined Under Namespace

Modules: Interceptors

Constant Summary collapse

ServingStatus =
::Grpc::Health::Checker::HealthCheckResponse::ServingStatus

Instance Method Summary collapse

Instance Method Details

#handle(service) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/grpcx/server.rb', line 40

def handle(service)
  service_name = nil
  if service.is_a?(Class) && service < GRPC::GenericService
    service_name = service.service_name
  elsif service.is_a?(GRPC::GenericService)
    service_name = service.class.service_name
  end

  health.add_status(service_name, ServingStatus::SERVING) if service_name
  super
end

#healthObject



52
53
54
# File 'lib/grpcx/server.rb', line 52

def health
  @health ||= ::Grpc::Health::Checker.new
end

#initialize(**opts) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/grpcx/server.rb', line 25

def initialize(**opts)
  opts[:pool_size] ||= ENV['GRPC_SERVER_THREADS'].to_i if ENV['GRPC_SERVER_THREADS']
  opts[:max_waiting_requests] ||= ENV['GRPC_SERVER_QUEUE'].to_i if ENV['GRPC_SERVER_QUEUE']

  # interceptors are fired in FIFO order.
  opts[:interceptors] ||= []
  opts[:interceptors].prepend Grpcx::Server::Interceptors::Rescue.new(self)
  opts[:interceptors].prepend Grpcx::Server::Interceptors::Instrumentation.new
  opts[:interceptors].prepend Grpcx::Server::Interceptors::ActiveRecord.new if defined?(::ActiveRecord)

  super.tap do
    handle(health)
  end
end