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(op, execution_time = nil) ⇒ Response

Returns a new instance of Response.

Parameters:

  • op (GRPC::ActiveCall::Operation)
  • execution_time (Float) (defaults to: nil)


28
29
30
31
32
33
34
35
36
# File 'lib/gruf/response.rb', line 28

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

Instance Attribute Details

#cancelledObject (readonly)

Returns the value of attribute cancelled.



22
23
24
# File 'lib/gruf/response.rb', line 22

def cancelled
  @cancelled
end

#deadlineObject (readonly)

Returns the value of attribute deadline.



22
23
24
# File 'lib/gruf/response.rb', line 22

def deadline
  @deadline
end

#execution_timeObject (readonly)

Returns the value of attribute execution_time.



22
23
24
# File 'lib/gruf/response.rb', line 22

def execution_time
  @execution_time
end

#metadataObject (readonly)

Returns the value of attribute metadata.



22
23
24
# File 'lib/gruf/response.rb', line 22

def 
  @metadata
end

#operationObject (readonly)

Returns the value of attribute operation.



22
23
24
# File 'lib/gruf/response.rb', line 22

def operation
  @operation
end

#trailing_metadataObject (readonly)

Returns the value of attribute trailing_metadata.



22
23
24
# File 'lib/gruf/response.rb', line 22

def 
  @trailing_metadata
end

Instance Method Details

#internal_execution_timeInteger

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

Returns:

  • (Integer)


50
51
52
53
# File 'lib/gruf/response.rb', line 50

def internal_execution_time
  key = Gruf.instrumentation_options.fetch(:output_metadata_timer, {}).fetch(:metadata_key, 'timer')
  [key].to_f
end

#messageObject

Return the message returned by the request



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

def message
  @message ||= op.execute
end