Class: Protocol::GRPC::Call
- Inherits:
-
Object
- Object
- Protocol::GRPC::Call
- Defined in:
- lib/protocol/grpc/call.rb
Overview
Represents context for a single RPC call.
Instance Attribute Summary collapse
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
- #The HTTP response.(HTTPresponse.) ⇒ Object readonly
- #The underlying HTTP request.(underlyingHTTPrequest.) ⇒ Object readonly
Class Method Summary collapse
-
.for(request, response = nil) ⇒ Object
Create a new RPC call context for the given request and response.
Instance Method Summary collapse
-
#deadline_exceeded? ⇒ Boolean
Check if the deadline has expired.
-
#initialize(request, response = nil, deadline: nil) ⇒ Call
constructor
Initialize a new RPC call context.
-
#metadata ⇒ Object
Extract metadata from request headers.
-
#peer ⇒ Object
Get peer information (client address).
-
#status ⇒ Object
Get the current gRPC status of the call.
- #The deadline for this call.=(deadline) ⇒ Object
-
#time_remaining ⇒ Object
Get the time remaining until the deadline.
-
#timeout ⇒ Object
Get the timeout requested by the client.
Constructor Details
#initialize(request, response = nil, deadline: nil) ⇒ Call
Initialize a new RPC call context.
30 31 32 33 34 |
# File 'lib/protocol/grpc/call.rb', line 30 def initialize(request, response = nil, deadline: nil) @request = request @response = response @deadline = deadline end |
Instance Attribute Details
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
43 44 45 |
# File 'lib/protocol/grpc/call.rb', line 43 def deadline @deadline end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
37 38 39 |
# File 'lib/protocol/grpc/call.rb', line 37 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
40 41 42 |
# File 'lib/protocol/grpc/call.rb', line 40 def response @response end |
#The HTTP response.(HTTPresponse.) ⇒ Object (readonly)
40 |
# File 'lib/protocol/grpc/call.rb', line 40 attr_reader :response |
#The underlying HTTP request.(underlyingHTTPrequest.) ⇒ Object (readonly)
37 |
# File 'lib/protocol/grpc/call.rb', line 37 attr_reader :request |
Class Method Details
.for(request, response = nil) ⇒ Object
Create a new RPC call context for the given request and response.
Automatically computes a deadline from the grpc-timeout request header, if present.
18 19 20 21 22 23 24 |
# File 'lib/protocol/grpc/call.rb', line 18 def self.for(request, response = nil) if timeout = request.headers["grpc-timeout"] deadline = Async::Deadline.start(timeout.to_seconds) end return new(request, response, deadline: deadline) end |
Instance Method Details
#deadline_exceeded? ⇒ Boolean
Check if the deadline has expired.
59 60 61 |
# File 'lib/protocol/grpc/call.rb', line 59 def deadline_exceeded? @deadline&.expired? || false end |
#metadata ⇒ Object
Extract metadata from request headers.
47 48 49 |
# File 'lib/protocol/grpc/call.rb', line 47 def @metadata ||= Metadata.extract(@request.headers) end |
#peer ⇒ Object
Get peer information (client address).
79 80 81 |
# File 'lib/protocol/grpc/call.rb', line 79 def peer @request.peer&.to_s end |
#status ⇒ Object
Get the current gRPC status of the call.
71 72 73 74 75 |
# File 'lib/protocol/grpc/call.rb', line 71 def status if headers = @response&.headers headers["grpc-status"]&.to_i end end |
#The deadline for this call.=(deadline) ⇒ Object
43 |
# File 'lib/protocol/grpc/call.rb', line 43 attr_reader :deadline |
#time_remaining ⇒ Object
Get the time remaining until the deadline.
65 66 67 |
# File 'lib/protocol/grpc/call.rb', line 65 def time_remaining @deadline&.remaining end |
#timeout ⇒ Object
Get the timeout requested by the client.
53 54 55 |
# File 'lib/protocol/grpc/call.rb', line 53 def timeout @request.headers["grpc-timeout"]&.to_seconds end |