Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Add LRO wrapper. #47

Merged
merged 7 commits into from
Nov 21, 2016
Merged

Add LRO wrapper. #47

merged 7 commits into from
Nov 21, 2016

Conversation

landrito
Copy link
Contributor

@landrito landrito commented Oct 25, 2016

Still needed:

  • Unit tests (Exponential retrying still needed)
  • Finished design review from gcloud-ruby

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

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.

@codecov-io
Copy link

codecov-io commented Oct 25, 2016

Current coverage is 99.44% (diff: 99.69%)

Merging #47 into master will increase coverage by 0.21%

@@             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          

Powered by Codecov. Last update 297c819...0319620

@landrito landrito force-pushed the lro branch 2 times, most recently from da356d6 to d33bd23 Compare October 25, 2016 19:32
)
@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.

This comment was marked as spam.

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

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

end
end

# TODO: Test exponential backoff.

This comment was marked as spam.

This comment was marked as spam.

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.

@landrito
Copy link
Contributor Author

landrito commented Nov 10, 2016

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.


# Cancels the operation.
def cancel
@client.cancel_operation @grpc_op.name

This comment was marked as spam.

This comment was marked as spam.

@grpc_op.response
end

def metadata(type: nil)

This comment was marked as spam.

This comment was marked as spam.

# @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.

@landrito landrito force-pushed the lro branch 3 times, most recently from 2678d0d to ef7cd43 Compare November 10, 2016 02:35
# @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.

# @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.

This comment was marked as spam.

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

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

@landrito landrito changed the title WIP Initial LRO wrapper. Add LRO wrapper. Nov 16, 2016
@landrito landrito merged commit e8c66e4 into googleapis:master Nov 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants