Class: Protocol::GRPC::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/grpc/call.rb

Overview

Represents context for a single RPC call.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#deadlineObject (readonly)

Returns the value of attribute deadline.



43
44
45
# File 'lib/protocol/grpc/call.rb', line 43

def deadline
  @deadline
end

#requestObject (readonly)

Returns the value of attribute request.



37
38
39
# File 'lib/protocol/grpc/call.rb', line 37

def request
  @request
end

#responseObject (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.

Returns:

  • (Boolean)


59
60
61
# File 'lib/protocol/grpc/call.rb', line 59

def deadline_exceeded?
	@deadline&.expired? || false
end

#metadataObject

Extract metadata from request headers.



47
48
49
# File 'lib/protocol/grpc/call.rb', line 47

def 
	@metadata ||= Metadata.extract(@request.headers)
end

#peerObject

Get peer information (client address).



79
80
81
# File 'lib/protocol/grpc/call.rb', line 79

def peer
	@request.peer&.to_s
end

#statusObject

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_remainingObject

Get the time remaining until the deadline.



65
66
67
# File 'lib/protocol/grpc/call.rb', line 65

def time_remaining
	@deadline&.remaining
end

#timeoutObject

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