google-gax 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google/gax.rb +1 -274
- data/lib/google/gax/api_callable.rb +0 -3
- data/lib/google/gax/bundling.rb +1 -1
- data/lib/google/gax/constants.rb +34 -0
- data/lib/google/gax/operation.rb +253 -0
- data/lib/google/gax/path_template.rb +3 -2
- data/lib/google/gax/settings.rb +275 -2
- data/lib/google/gax/version.rb +1 -1
- data/lib/google/longrunning/{operations_api.rb → operations_client.rb} +34 -53
- data/spec/google/gax/operation_spec.rb +338 -0
- metadata +21 -4
@@ -63,8 +63,9 @@ module Google
|
|
63
63
|
raise 'path template has no segments' if segments.nil?
|
64
64
|
segments.each do |s|
|
65
65
|
next unless s.kind == TERMINAL && s.literal == '**'
|
66
|
-
|
67
|
-
|
66
|
+
if has_path_wildcard
|
67
|
+
raise 'path template cannot contain more than one path wildcard'
|
68
|
+
end
|
68
69
|
has_path_wildcard = true
|
69
70
|
end
|
70
71
|
segments
|
data/lib/google/gax/settings.rb
CHANGED
@@ -29,6 +29,281 @@
|
|
29
29
|
|
30
30
|
module Google
|
31
31
|
module Gax
|
32
|
+
# rubocop:disable Metrics/ParameterLists
|
33
|
+
|
34
|
+
# Encapsulates the call settings for an ApiCallable
|
35
|
+
# @!attribute [r] timeout
|
36
|
+
# @return [Numeric]
|
37
|
+
# @!attribute [r] retry_options
|
38
|
+
# @return [RetryOptions]
|
39
|
+
# @!attribute [r] page_descriptor
|
40
|
+
# @return [PageDescriptor]
|
41
|
+
# @!attribute [r] page_token
|
42
|
+
# @return [Object]
|
43
|
+
# @!attribute [r] bundle_descriptor
|
44
|
+
# @return [BundleDescriptor]
|
45
|
+
# @!attribute [r] kwargs
|
46
|
+
# @return [Hash]
|
47
|
+
class CallSettings
|
48
|
+
attr_reader :timeout, :retry_options, :page_descriptor, :page_token,
|
49
|
+
:bundler, :bundle_descriptor, :kwargs, :errors
|
50
|
+
|
51
|
+
# @param timeout [Numeric] The client-side timeout for API calls. This
|
52
|
+
# parameter is ignored for retrying calls.
|
53
|
+
# @param retry_options [RetryOptions] The configuration for retrying upon
|
54
|
+
# transient error. If set to nil, this call will not retry.
|
55
|
+
# @param page_descriptor [PageDescriptor] indicates the structure of page
|
56
|
+
# streaming to be performed. If set to nil, page streaming is not
|
57
|
+
# performed.
|
58
|
+
# @param page_token [Object] determines the page token used in the
|
59
|
+
# page streaming request. If there is no page_descriptor, this has no
|
60
|
+
# meaning.
|
61
|
+
# @param bundler orchestrates bundling. If nil, bundling is not
|
62
|
+
# performed.
|
63
|
+
# @param bundle_descriptor [BundleDescriptor] indicates the structure of
|
64
|
+
# the bundle. If nil, bundling is not performed.
|
65
|
+
# @param kwargs [Hash]
|
66
|
+
# Additional keyword argments to be passed to the API call.
|
67
|
+
# @param errors [Array<Exception>]
|
68
|
+
# Configures the exceptions to wrap with GaxError.
|
69
|
+
def initialize(timeout: 30, retry_options: nil, page_descriptor: nil,
|
70
|
+
page_token: nil, bundler: nil, bundle_descriptor: nil,
|
71
|
+
kwargs: {}, errors: [])
|
72
|
+
@timeout = timeout
|
73
|
+
@retry_options = retry_options
|
74
|
+
@page_descriptor = page_descriptor
|
75
|
+
@page_token = page_token
|
76
|
+
@bundler = bundler
|
77
|
+
@bundle_descriptor = bundle_descriptor
|
78
|
+
@kwargs = kwargs
|
79
|
+
@errors = errors
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return true when it has retry codes.
|
83
|
+
def retry_codes?
|
84
|
+
@retry_options && @retry_options.retry_codes
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return true when it has valid bundler configuration.
|
88
|
+
def bundler?
|
89
|
+
@bundler && @bundle_descriptor
|
90
|
+
end
|
91
|
+
|
92
|
+
# Creates a new CallSetting instance which is based on this but merged
|
93
|
+
# settings from options.
|
94
|
+
# @param options [CallOptions, nil] The overriding call settings.
|
95
|
+
# @return a new merged call settings.
|
96
|
+
def merge(options)
|
97
|
+
unless options
|
98
|
+
return CallSettings.new(timeout: @timeout,
|
99
|
+
retry_options: @retry_options,
|
100
|
+
page_descriptor: @page_descriptor,
|
101
|
+
page_token: @page_token,
|
102
|
+
bundler: @bundler,
|
103
|
+
bundle_descriptor: @bundle_descriptor,
|
104
|
+
kwargs: @kwargs,
|
105
|
+
errors: @errors)
|
106
|
+
end
|
107
|
+
|
108
|
+
timeout = if options.timeout == :OPTION_INHERIT
|
109
|
+
@timeout
|
110
|
+
else
|
111
|
+
options.timeout
|
112
|
+
end
|
113
|
+
retry_options = if options.retry_options == :OPTION_INHERIT
|
114
|
+
@retry_options
|
115
|
+
else
|
116
|
+
options.retry_options
|
117
|
+
end
|
118
|
+
page_token = if options.page_token == :OPTION_INHERIT
|
119
|
+
@page_token
|
120
|
+
else
|
121
|
+
options.page_token
|
122
|
+
end
|
123
|
+
|
124
|
+
kwargs = @kwargs.dup
|
125
|
+
kwargs.update(options.kwargs) if options.kwargs != :OPTION_INHERIT
|
126
|
+
|
127
|
+
CallSettings.new(timeout: timeout,
|
128
|
+
retry_options: retry_options,
|
129
|
+
page_descriptor: @page_descriptor,
|
130
|
+
page_token: page_token,
|
131
|
+
bundler: @bundler,
|
132
|
+
bundle_descriptor: @bundle_descriptor,
|
133
|
+
kwargs: kwargs,
|
134
|
+
errors: @errors)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
private_constant :CallSettings
|
139
|
+
|
140
|
+
# Encapsulates the overridable settings for a particular API call
|
141
|
+
# @!attribute [r] timeout
|
142
|
+
# @return [Numeric, :OPTION_INHERIT]
|
143
|
+
# @!attribute [r] retry_options
|
144
|
+
# @return [RetryOptions, :OPTION_INHERIT]
|
145
|
+
# @!attribute [r] page_token
|
146
|
+
# @return [Object, :OPTION_INHERIT, :INITIAL_PAGE]
|
147
|
+
# @!attribute [r] kwargs
|
148
|
+
# @return [Hash, :OPTION_INHERIT]
|
149
|
+
class CallOptions
|
150
|
+
attr_reader :timeout, :retry_options, :page_token, :kwargs
|
151
|
+
|
152
|
+
# @param timeout [Numeric, :OPTION_INHERIT]
|
153
|
+
# The client-side timeout for API calls.
|
154
|
+
# @param retry_options [RetryOptions, :OPTION_INHERIT]
|
155
|
+
# The configuration for retrying upon transient error.
|
156
|
+
# If set to nil, this call will not retry.
|
157
|
+
# @param page_token [Object, :OPTION_INHERIT]
|
158
|
+
# If set and the call is configured for page streaming, page streaming
|
159
|
+
# is starting with this page_token.
|
160
|
+
# @param kwargs [Hash, :OPTION_INHERIT]
|
161
|
+
# Additional keyword argments to be passed to the API call.
|
162
|
+
def initialize(timeout: :OPTION_INHERIT,
|
163
|
+
retry_options: :OPTION_INHERIT,
|
164
|
+
page_token: :OPTION_INHERIT,
|
165
|
+
kwargs: :OPTION_INHERIT)
|
166
|
+
@timeout = timeout
|
167
|
+
@retry_options = retry_options
|
168
|
+
@page_token = page_token
|
169
|
+
@kwargs = kwargs
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Describes the structure of a page-streaming call.
|
174
|
+
class PageDescriptor < Struct.new(:request_page_token_field,
|
175
|
+
:response_page_token_field,
|
176
|
+
:resource_field)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Per-call configurable settings for retrying upon transient failure.
|
180
|
+
class RetryOptions < Struct.new(:retry_codes, :backoff_settings)
|
181
|
+
# @!attribute retry_codes
|
182
|
+
# @return [Array<Grpc::Code>] a list of exceptions upon which
|
183
|
+
# a retry should be attempted.
|
184
|
+
# @!attribute backoff_settings
|
185
|
+
# @return [BackoffSettings] configuring the retry exponential
|
186
|
+
# backoff algorithm.
|
187
|
+
end
|
188
|
+
|
189
|
+
# Parameters to the exponential backoff algorithm for retrying.
|
190
|
+
class BackoffSettings < Struct.new(
|
191
|
+
:initial_retry_delay_millis,
|
192
|
+
:retry_delay_multiplier,
|
193
|
+
:max_retry_delay_millis,
|
194
|
+
:initial_rpc_timeout_millis,
|
195
|
+
:rpc_timeout_multiplier,
|
196
|
+
:max_rpc_timeout_millis,
|
197
|
+
:total_timeout_millis
|
198
|
+
)
|
199
|
+
# @!attribute initial_retry_delay_millis
|
200
|
+
# @return [Numeric] the initial delay time, in milliseconds,
|
201
|
+
# between the completion of the first failed request and the
|
202
|
+
# initiation of the first retrying request.
|
203
|
+
# @!attribute retry_delay_multiplier
|
204
|
+
# @return [Numeric] the multiplier by which to increase the
|
205
|
+
# delay time between the completion of failed requests, and
|
206
|
+
# the initiation of the subsequent retrying request.
|
207
|
+
# @!attribute max_retry_delay_millis
|
208
|
+
# @return [Numeric] the maximum delay time, in milliseconds,
|
209
|
+
# between requests. When this value is reached,
|
210
|
+
# +retry_delay_multiplier+ will no longer be used to
|
211
|
+
# increase delay time.
|
212
|
+
# @!attribute initial_rpc_timeout_millis
|
213
|
+
# @return [Numeric] the initial timeout parameter to the request.
|
214
|
+
# @!attribute rpc_timeout_multiplier
|
215
|
+
# @return [Numeric] the multiplier by which to increase the
|
216
|
+
# timeout parameter between failed requests.
|
217
|
+
# @!attribute max_rpc_timeout_millis
|
218
|
+
# @return [Numeric] the maximum timeout parameter, in
|
219
|
+
# milliseconds, for a request. When this value is reached,
|
220
|
+
# +rpc_timeout_multiplier+ will no longer be used to
|
221
|
+
# increase the timeout.
|
222
|
+
# @!attribute total_timeout_millis
|
223
|
+
# @return [Numeric] the total time, in milliseconds, starting
|
224
|
+
# from when the initial request is sent, after which an
|
225
|
+
# error will be returned, regardless of the retrying
|
226
|
+
# attempts made meanwhile.
|
227
|
+
end
|
228
|
+
|
229
|
+
# Describes the structure of bundled call.
|
230
|
+
#
|
231
|
+
# request_discriminator_fields may include '.' as a separator, which is
|
232
|
+
# used to indicate object traversal. This allows fields in nested objects
|
233
|
+
# to be used to determine what requests to bundle.
|
234
|
+
class BundleDescriptor < Struct.new(:bundled_field,
|
235
|
+
:request_discriminator_fields,
|
236
|
+
:subresponse_field)
|
237
|
+
# @!attribute bundled_field
|
238
|
+
# @return [String] the repeated field in the request message
|
239
|
+
# that will have its elements aggregated by bundling.
|
240
|
+
# @!attribute request_discriminator_fields
|
241
|
+
# @return [Array<String>] a list of fields in the target
|
242
|
+
# request message class that are used to determine which
|
243
|
+
# messages should be bundled together.
|
244
|
+
# @!attribute subresponse_field
|
245
|
+
# @return [String] an optional field, when present it
|
246
|
+
# indicates the field in the response message that should be
|
247
|
+
# used to demultiplex the response into multiple response
|
248
|
+
# messages.
|
249
|
+
def initialize(bundled_field, request_discriminator_fields,
|
250
|
+
subresponse_field: nil)
|
251
|
+
super(bundled_field, request_discriminator_fields, subresponse_field)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# Holds values used to configure bundling.
|
256
|
+
#
|
257
|
+
# The xxx_threshold attributes are used to configure when the bundled
|
258
|
+
# request should be made.
|
259
|
+
class BundleOptions < Struct.new(:element_count_threshold,
|
260
|
+
:element_count_limit,
|
261
|
+
:request_byte_threshold,
|
262
|
+
:request_byte_limit,
|
263
|
+
:delay_threshold_millis)
|
264
|
+
# @!attribute element_count_threshold
|
265
|
+
# @return [Numeric] the bundled request will be sent once the
|
266
|
+
# count of outstanding elements in the repeated field
|
267
|
+
# reaches this value.
|
268
|
+
# @!attribute element_count_limit
|
269
|
+
# @return [Numeric] represents a hard limit on the number of
|
270
|
+
# elements in the repeated field of the bundle; if adding a
|
271
|
+
# request to a bundle would exceed this value, the bundle is
|
272
|
+
# sent and the new request is added to a fresh bundle. It is
|
273
|
+
# invalid for a single request to exceed this limit.
|
274
|
+
# @!attribute request_byte_threshold
|
275
|
+
# @return [Numeric] the bundled request will be sent once the
|
276
|
+
# count of bytes in the request reaches this value. Note
|
277
|
+
# that this value is pessimistically approximated by summing
|
278
|
+
# the bytesizes of the elements in the repeated field, and
|
279
|
+
# therefore may be an under-approximation.
|
280
|
+
# @!attribute request_byte_limit
|
281
|
+
# @return [Numeric] represents a hard limit on the size of the
|
282
|
+
# bundled request; if adding a request to a bundle would
|
283
|
+
# exceed this value, the bundle is sent and the new request
|
284
|
+
# is added to a fresh bundle. It is invalid for a single
|
285
|
+
# request to exceed this limit. Note that this value is
|
286
|
+
# pessimistically approximated by summing the bytesizes of
|
287
|
+
# the elements in the repeated field, with a buffer applied
|
288
|
+
# to correspond to the resulting under-approximation.
|
289
|
+
# @!attribute delay_threshold_millis
|
290
|
+
# @return [Numeric] the bundled request will be sent this
|
291
|
+
# amount of time after the first element in the bundle was
|
292
|
+
# added to it.
|
293
|
+
def initialize(element_count_threshold: 0,
|
294
|
+
element_count_limit: 0,
|
295
|
+
request_byte_threshold: 0,
|
296
|
+
request_byte_limit: 0,
|
297
|
+
delay_threshold_millis: 0)
|
298
|
+
super(
|
299
|
+
element_count_threshold,
|
300
|
+
element_count_limit,
|
301
|
+
request_byte_threshold,
|
302
|
+
request_byte_limit,
|
303
|
+
delay_threshold_millis)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
32
307
|
# Helper for #construct_settings
|
33
308
|
#
|
34
309
|
# @param bundle_config A Hash specifying a bundle parameters, the value for
|
@@ -117,8 +392,6 @@ module Google
|
|
117
392
|
string.scan(/[[:upper:]][^[:upper:]]*/).map(&:downcase).join('_')
|
118
393
|
end
|
119
394
|
|
120
|
-
# rubocop:disable Metrics/ParameterLists
|
121
|
-
|
122
395
|
# Constructs a dictionary mapping method names to CallSettings.
|
123
396
|
#
|
124
397
|
# The +client_config+ parameter is parsed from a client configuration JSON
|
data/lib/google/gax/version.rb
CHANGED
@@ -26,6 +26,7 @@ require "json"
|
|
26
26
|
require "pathname"
|
27
27
|
|
28
28
|
require "google/gax"
|
29
|
+
require "google/longrunning/operations_pb"
|
29
30
|
|
30
31
|
module Google
|
31
32
|
module Longrunning
|
@@ -41,7 +42,7 @@ module Google
|
|
41
42
|
#
|
42
43
|
# @!attribute [r] operations_stub
|
43
44
|
# @return [Google::Longrunning::Operations::Stub]
|
44
|
-
class
|
45
|
+
class OperationsClient
|
45
46
|
attr_reader :operations_stub
|
46
47
|
|
47
48
|
# The default address of the service.
|
@@ -68,28 +69,6 @@ module Google
|
|
68
69
|
ALL_SCOPES = [
|
69
70
|
].freeze
|
70
71
|
|
71
|
-
OPERATION_PATH_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
72
|
-
"operations/{operation_path=**}"
|
73
|
-
)
|
74
|
-
|
75
|
-
private_constant :OPERATION_PATH_PATH_TEMPLATE
|
76
|
-
|
77
|
-
# Returns a fully-qualified operation_path resource name string.
|
78
|
-
# @param operation_path [String]
|
79
|
-
# @return [String]
|
80
|
-
def self.operation_path_path operation_path
|
81
|
-
OPERATION_PATH_PATH_TEMPLATE.render(
|
82
|
-
:"operation_path" => operation_path
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Parses the operation_path from a operation_path resource.
|
87
|
-
# @param operation_path_name [String]
|
88
|
-
# @return [String]
|
89
|
-
def self.match_operation_path_from_operation_path_name operation_path_name
|
90
|
-
OPERATION_PATH_PATH_TEMPLATE.match(operation_path_name)["operation_path"]
|
91
|
-
end
|
92
|
-
|
93
72
|
# @param service_path [String]
|
94
73
|
# The domain name of the API remote host.
|
95
74
|
# @param port [Integer]
|
@@ -185,20 +164,20 @@ module Google
|
|
185
164
|
# @return [Google::Longrunning::Operation]
|
186
165
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
187
166
|
# @example
|
188
|
-
# require "google/longrunning/
|
167
|
+
# require "google/longrunning/operations_client"
|
189
168
|
#
|
190
|
-
#
|
169
|
+
# OperationsClient = Google::Longrunning::OperationsClient
|
191
170
|
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
# response =
|
171
|
+
# operations_client = OperationsClient.new
|
172
|
+
# name = ''
|
173
|
+
# response = operations_client.get_operation(name)
|
195
174
|
|
196
175
|
def get_operation \
|
197
176
|
name,
|
198
177
|
options: nil
|
199
|
-
req = Google::Longrunning::GetOperationRequest.new(
|
178
|
+
req = Google::Longrunning::GetOperationRequest.new({
|
200
179
|
name: name
|
201
|
-
)
|
180
|
+
}.delete_if { |_, v| v.nil? })
|
202
181
|
@get_operation.call(req, options)
|
203
182
|
end
|
204
183
|
|
@@ -228,21 +207,21 @@ module Google
|
|
228
207
|
# object.
|
229
208
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
230
209
|
# @example
|
231
|
-
# require "google/longrunning/
|
210
|
+
# require "google/longrunning/operations_client"
|
232
211
|
#
|
233
|
-
#
|
212
|
+
# OperationsClient = Google::Longrunning::OperationsClient
|
234
213
|
#
|
235
|
-
#
|
214
|
+
# operations_client = OperationsClient.new
|
236
215
|
# name = ''
|
237
216
|
# filter = ''
|
238
217
|
#
|
239
218
|
# # Iterate over all results.
|
240
|
-
#
|
219
|
+
# operations_client.list_operations(name, filter).each do |element|
|
241
220
|
# # Process element.
|
242
221
|
# end
|
243
222
|
#
|
244
223
|
# # Or iterate over results one page at a time.
|
245
|
-
#
|
224
|
+
# operations_client.list_operations(name, filter).each_page do |page|
|
246
225
|
# # Process each page at a time.
|
247
226
|
# page.each do |element|
|
248
227
|
# # Process element.
|
@@ -254,11 +233,11 @@ module Google
|
|
254
233
|
filter,
|
255
234
|
page_size: nil,
|
256
235
|
options: nil
|
257
|
-
req = Google::Longrunning::ListOperationsRequest.new(
|
236
|
+
req = Google::Longrunning::ListOperationsRequest.new({
|
258
237
|
name: name,
|
259
|
-
filter: filter
|
260
|
-
|
261
|
-
|
238
|
+
filter: filter,
|
239
|
+
page_size: page_size
|
240
|
+
}.delete_if { |_, v| v.nil? })
|
262
241
|
@list_operations.call(req, options)
|
263
242
|
end
|
264
243
|
|
@@ -280,21 +259,22 @@ module Google
|
|
280
259
|
# retries, etc.
|
281
260
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
282
261
|
# @example
|
283
|
-
# require "google/longrunning/
|
262
|
+
# require "google/longrunning/operations_client"
|
284
263
|
#
|
285
|
-
#
|
264
|
+
# OperationsClient = Google::Longrunning::OperationsClient
|
286
265
|
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
266
|
+
# operations_client = OperationsClient.new
|
267
|
+
# name = ''
|
268
|
+
# operations_client.cancel_operation(name)
|
290
269
|
|
291
270
|
def cancel_operation \
|
292
271
|
name,
|
293
272
|
options: nil
|
294
|
-
req = Google::Longrunning::CancelOperationRequest.new(
|
273
|
+
req = Google::Longrunning::CancelOperationRequest.new({
|
295
274
|
name: name
|
296
|
-
)
|
275
|
+
}.delete_if { |_, v| v.nil? })
|
297
276
|
@cancel_operation.call(req, options)
|
277
|
+
nil
|
298
278
|
end
|
299
279
|
|
300
280
|
# Deletes a long-running operation. This method indicates that the client is
|
@@ -309,21 +289,22 @@ module Google
|
|
309
289
|
# retries, etc.
|
310
290
|
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
311
291
|
# @example
|
312
|
-
# require "google/longrunning/
|
292
|
+
# require "google/longrunning/operations_client"
|
313
293
|
#
|
314
|
-
#
|
294
|
+
# OperationsClient = Google::Longrunning::OperationsClient
|
315
295
|
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
296
|
+
# operations_client = OperationsClient.new
|
297
|
+
# name = ''
|
298
|
+
# operations_client.delete_operation(name)
|
319
299
|
|
320
300
|
def delete_operation \
|
321
301
|
name,
|
322
302
|
options: nil
|
323
|
-
req = Google::Longrunning::DeleteOperationRequest.new(
|
303
|
+
req = Google::Longrunning::DeleteOperationRequest.new({
|
324
304
|
name: name
|
325
|
-
)
|
305
|
+
}.delete_if { |_, v| v.nil? })
|
326
306
|
@delete_operation.call(req, options)
|
307
|
+
nil
|
327
308
|
end
|
328
309
|
end
|
329
310
|
end
|