Class: RubyWorker::Server
- Inherits:
-
Object
- Object
- RubyWorker::Server
- Defined in:
- lib/ruby_worker/server.rb
Overview
Server is the gRPC entry. Implements the universal ‘revund.worker.v1.Worker` contract — same shape as ts-worker and php-worker. Bind, advertise readiness on stdout, register the service, serve.
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
-
#initialize(port) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(port) ⇒ Server
Returns a new instance of Server.
14 15 16 |
# File 'lib/ruby_worker/server.rb', line 14 def initialize(port) @port = port end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_worker/server.rb', line 18 def run server = GRPC::RpcServer.new server.add_http2_port("0.0.0.0:#{@port}", :this_port_is_insecure) server.handle(RubyWorker::Service.new) # Liveness ping for parent processes that spawn this worker # as a sidecar. $stdout.puts("ready: 0.0.0.0:#{@port}") $stdout.flush # Graceful shutdown on SIGTERM / SIGINT. %w[TERM INT].each do |sig| trap(sig) { server.stop } end server.run_till_terminated end |