Class: Gruf::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/response.rb

Overview

Wraps the active call operation to provide metadata and timing around the request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation:, message:, execution_time: nil) ⇒ Response

Initialize a response object with the given gRPC operation

Parameters:

  • operation (GRPC::ActiveCall::Operation)

    The given operation for the current call

  • message (StdClass)
  • execution_time (Float) (defaults to: nil)

    The amount of time that the response took to occur



49
50
51
52
53
54
55
56
57
# File 'lib/gruf/response.rb', line 49

def initialize(operation:, message:, execution_time: nil)
  @operation = operation
  @message = message
  @metadata = operation.
  @trailing_metadata = operation.
  @deadline = operation.deadline
  @cancelled = operation.cancelled?
  @execution_time = execution_time || 0.0
end

Instance Attribute Details

#cancelledObject (readonly)

Returns the value of attribute cancelled.



37
38
39
# File 'lib/gruf/response.rb', line 37

def cancelled
  @cancelled
end

#deadlineObject (readonly)

Returns the value of attribute deadline.



34
35
36
# File 'lib/gruf/response.rb', line 34

def deadline
  @deadline
end

#execution_timeObject (readonly)

Returns the value of attribute execution_time.



40
41
42
# File 'lib/gruf/response.rb', line 40

def execution_time
  @execution_time
end

#metadataObject (readonly)

Returns the value of attribute metadata.



28
29
30
# File 'lib/gruf/response.rb', line 28

def 
  @metadata
end

#operationObject (readonly)

Returns the value of attribute operation.



25
26
27
# File 'lib/gruf/response.rb', line 25

def operation
  @operation
end

#trailing_metadataObject (readonly)

Returns the value of attribute trailing_metadata.



31
32
33
# File 'lib/gruf/response.rb', line 31

def 
  @trailing_metadata
end

Instance Method Details

#internal_execution_timeFloat

Return execution time of the call internally on the server in ms

Returns:

  • (Float)

    The execution time of the response



73
74
75
# File 'lib/gruf/response.rb', line 73

def internal_execution_time
  ['timer'].to_f
end

#messageObject

Return the message returned by the request

Returns:

  • (Object)

    The protobuf response message



64
65
66
# File 'lib/gruf/response.rb', line 64

def message
  @message ||= @operation.execute
end