Class: AnyCable::Server
- Inherits:
-
Object
- Object
- AnyCable::Server
- Defined in:
- lib/anycable/server.rb
Overview
Constant Summary collapse
- DEFAULT_HOST =
"0.0.0.0:50051"
Instance Attribute Summary collapse
-
#grpc_server ⇒ Object
readonly
Returns the value of attribute grpc_server.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
-
.start(**options) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Instance Method Summary collapse
-
#initialize(host: DEFAULT_HOST, logger: AnyCable.logger, **options) ⇒ Server
constructor
A new instance of Server.
- #running? ⇒ Boolean
-
#start ⇒ Object
Start gRPC server in background and wait untill it ready to accept connections.
-
#stop ⇒ Object
Stop gRPC server if it’s running.
- #stopped? ⇒ Boolean
- #wait_till_terminated ⇒ Object
Constructor Details
#initialize(host: DEFAULT_HOST, logger: AnyCable.logger, **options) ⇒ Server
Returns a new instance of Server.
70 71 72 73 74 |
# File 'lib/anycable/server.rb', line 70 def initialize(host: DEFAULT_HOST, logger: AnyCable.logger, **) @logger = logger @host = host @grpc_server = build_server() end |
Instance Attribute Details
#grpc_server ⇒ Object (readonly)
Returns the value of attribute grpc_server.
68 69 70 |
# File 'lib/anycable/server.rb', line 68 def grpc_server @grpc_server end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
68 69 70 |
# File 'lib/anycable/server.rb', line 68 def host @host end |
Class Method Details
.start(**options) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
26 27 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 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/anycable/server.rb', line 26 def start(**) warn <<~DEPRECATION Using AnyCable::Server.start is deprecated! Please, use anycable CLI instead. See https://docs.anycable.io/#upgrade_to_0_6_0 DEPRECATION AnyCable.server_callbacks.each(&:call) server = new( host: AnyCable.config.rpc_host, **AnyCable.config.to_grpc_params, interceptors: AnyCable.middleware.to_a, ** ) AnyCable.middleware.freeze if AnyCable.config.http_health_port_provided? health_server = AnyCable::HealthServer.new( server, **AnyCable.config.to_http_health_params ) health_server.start end at_exit do server.stop health_server&.stop end AnyCable.logger.info "Broadcasting Redis channel: #{AnyCable.config.redis_channel}" server.start server.wait_till_terminated end |
Instance Method Details
#running? ⇒ Boolean
107 108 109 |
# File 'lib/anycable/server.rb', line 107 def running? grpc_server.running_state == :running end |
#start ⇒ Object
Start gRPC server in background and wait untill it ready to accept connections
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/anycable/server.rb', line 78 def start return if running? raise "Cannot re-start stopped server" if stopped? logger.info "RPC server is starting..." @start_thread = Thread.new { grpc_server.run } grpc_server.wait_till_running logger.info "RPC server is listening on #{host}" end |
#stop ⇒ Object
Stop gRPC server if it’s running
99 100 101 102 103 104 105 |
# File 'lib/anycable/server.rb', line 99 def stop return unless running? grpc_server.stop logger.info "RPC server stopped" end |
#stopped? ⇒ Boolean
111 112 113 |
# File 'lib/anycable/server.rb', line 111 def stopped? grpc_server.running_state == :stopped end |
#wait_till_terminated ⇒ Object
92 93 94 95 96 |
# File 'lib/anycable/server.rb', line 92 def wait_till_terminated raise "Server is not running" unless running? start_thread.join end |