Class: Anyt::RPC

Inherits:
Object
  • Object
show all
Defined in:
lib/anyt/rpc.rb

Overview

Runs AnyCable RPC server in the background

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#runningObject

Returns the value of attribute running.



12
13
14
# File 'lib/anyt/rpc.rb', line 12

def running
  @running
end

#serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/anyt/rpc.rb', line 13

def server
  @server
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/anyt/rpc.rb', line 15

def start
  AnyCable.logger.debug "Starting RPC server ..."

  AnyCable.server_callbacks.each(&:call)

  @server = AnyCable::GRPC::Server.new(
    host: AnyCable.config.rpc_host,
    **AnyCable.config.to_grpc_params
  )

  if defined?(::AnyCable::Middlewares::EnvSid)
    AnyCable.middleware.use(::AnyCable::Middlewares::EnvSid)
  end

  AnyCable.middleware.freeze

  server.start

  AnyCable.logger.debug "RPC server started"
end

#stopObject

rubocop: enable Metrics/AbcSize,Metrics/MethodLength



37
38
39
# File 'lib/anyt/rpc.rb', line 37

def stop
  server&.stop
end