Class: EventHookClientServer::Server

Inherits:
V1::Services::EventHook::Service show all
Extended by:
DefinitionHelpers
Defined in:
lib/event_hook_client_server/server.rb,
lib/event_hook_client_server/server/request_processor.rb,
lib/event_hook_client_server/server/definition_helpers.rb

Defined Under Namespace

Modules: DefinitionHelpers Classes: RequestProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DefinitionHelpers

generic_rpc

Constructor Details

#initialize(*args, logger: nil) ⇒ Server

Returns a new instance of Server.



47
48
49
50
# File 'lib/event_hook_client_server/server.rb', line 47

def initialize(*args, logger: nil)
  @logger = logger || self.logger
  super(*args)
end

Instance Attribute Details

#find_integration_from_headers_handlerObject

Returns the value of attribute find_integration_from_headers_handler.



79
80
81
# File 'lib/event_hook_client_server/server.rb', line 79

def find_integration_from_headers_handler
  @find_integration_from_headers_handler
end

#handlerObject

Returns the value of attribute handler.



45
46
47
# File 'lib/event_hook_client_server/server.rb', line 45

def handler
  @handler
end

#loggerObject



72
73
74
# File 'lib/event_hook_client_server/server.rb', line 72

def logger
  @logger ||= Logger.new(STDOUT)
end

Class Method Details

.default_configObject



36
37
38
39
40
41
42
# File 'lib/event_hook_client_server/server.rb', line 36

def self.default_config
  @default_config ||= DEFAULT_CONFIG.dup.tap do |config|
    if defined?(ElasticAPM::GRPC::ClientInterceptor)
      config[:interceptors] << ElasticAPM::GRPC::ClientInterceptor.new
    end
  end
end

Instance Method Details

#find_integration_from_headers(input, request) ⇒ Object



81
82
83
# File 'lib/event_hook_client_server/server.rb', line 81

def find_integration_from_headers(input, request)
  process_request(__method__, input, request)
end

#start!(binding_address: '0.0.0.0:3000', logger: nil, config: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/event_hook_client_server/server.rb', line 52

def start!(binding_address: '0.0.0.0:3000', logger: nil, config: nil)
  self.logger = logger unless logger.nil?

  config = self.class.default_config.merge(config || {})
  self.server = ::GRPC::RpcServer.new(config)
  server.add_http2_port(binding_address, :this_port_is_insecure)

  self.logger
      .info("EventHook SERVER starting on '#{binding_address}'")

  server.handle(self)
  server.run_till_terminated
end

#stop!Object



66
67
68
69
70
# File 'lib/event_hook_client_server/server.rb', line 66

def stop!
  return unless server

  server.stop
end