-
Notifications
You must be signed in to change notification settings - Fork 22
Conversation
# The client that handles the grpc operations. | ||
def initialize(grpc_op, client: nil) | ||
@grpc_op = grpc_op | ||
@client = client.nil? Google::Longrunning::OperationsApi.new : client |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def results | ||
return nil unless done? | ||
return @grpc_op.error if @grpc_op.result == :error | ||
@grpc_op.response.value if @grpc_op.result == :response |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Current coverage is 99.44% (diff: 99.69%)@@ master #47 diff @@
==========================================
Files 10 13 +3
Lines 1170 1453 +283
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1161 1445 +284
+ Misses 9 8 -1
Partials 0 0
|
da356d6
to
d33bd23
Compare
) | ||
@grpc_op = @client.get_operation @grpc_op.name, options: options | ||
if done? | ||
callbacks.each { |proc| proc.call(results) } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# Registers a callback to be run when a refreshed operation is marked | ||
# as done. If the operation has completed prior to a call to this function | ||
# the callback will be called instead of registered. | ||
def on_done |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# as done. If the operation has completed prior to a call to this function | ||
# the callback will be called instead of registered. | ||
def on_done(&block) | ||
if done? |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
end | ||
end | ||
|
||
# TODO: Test exponential backoff. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return @grpc_op.error if error? | ||
return @grpc_op.response.unpack(response_type) if response_type | ||
@grpc_op.response | ||
end |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Added some logic to unpack results based on the response. And the test for exponential backoff. @jmuk PTAL |
# unpacked from the response. If the response is not of the type provided | ||
# nil will be returned. | ||
# | ||
# @param [Class] The class type to be unpacked from the response. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
# Cancels the operation. | ||
def cancel | ||
@client.cancel_operation @grpc_op.name |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@grpc_op.response | ||
end | ||
|
||
def metadata(type: nil) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# @return [Google::Gax::CallOptions] The call options used when reloading | ||
# the operation. | ||
class Operation | ||
attr_reader :grpc_op, :client |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
2678d0d
to
ef7cd43
Compare
# @attribute [r] grpc_op | ||
# @return [Google::Longrunning::Operation] The wrapped grpc | ||
# operation object. | ||
# @attribute [r] client |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# @example General usage example | ||
# require 'google/gax/operation' | ||
# | ||
# op = Google::Gax::Operation.new api.methodThatReturnsOperation(name) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# Google::Protobuf::DescriptorPool.generated_pool. | ||
# If the type cannot be found the raw response is retuned. | ||
# | ||
# @param type [Class]] The class type to be unpacked from the response. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# Google::Protobuf::DescriptorPool.generated_pool. | ||
# If the type cannot be found the raw metadata is retuned. | ||
# | ||
# @param type [Class]] The class type to be unpacked from the response. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Still needed: