Skip to content

Commit

Permalink
feat(core): Add support for retry options to be configurable (googlea…
Browse files Browse the repository at this point in the history
  • Loading branch information
bajajneha27 authored May 14, 2022
1 parent 91ae8ff commit c575049
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions google-apis-core/lib/google/apis/core/http_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def execute(client)
begin
Retriable.retriable tries: options.retries + 1,
max_elapsed_time: options.max_elapsed_time,
base_interval: 1,
multiplier: 2,
base_interval: options.base_interval,
max_interval: options.max_interval,
multiplier: options.multiplier,
on: RETRIABLE_ERRORS do |try|
# This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
# auth to be re-attempted without having to retry all sorts of other failures like
Expand Down
13 changes: 13 additions & 0 deletions google-apis-core/lib/google/apis/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module Apis
:authorization,
:retries,
:max_elapsed_time,
:base_interval,
:max_interval,
:multiplier,
:header,
:normalize_unicode,
:skip_serialization,
Expand Down Expand Up @@ -69,6 +72,13 @@ class RequestOptions
# @return [Fixnum] Number of times to retry requests on server error.
# @!attribute [rw] max_elapsed_time
# @return [Fixnum] Total time in seconds that requests are allowed to keep being retried.
# @!attribute [rw] base_interval
# @return [Float] The initial interval in seconds between tries.
# @!attribute [rw] max_interval
# @return [Fixnum] The maximum interval in seconds that any individual retry can reach.
# @!attribute [rw] multiplier
# @return [rw] Each successive interval grows by this factor. A multipler of 1.5 means the next interval
# will be 1.5x the current interval.
# @!attribute [rw] header
# @return [Hash<String,String>] Additional HTTP headers to include in requests.
# @!attribute [rw] normalize_unicode
Expand Down Expand Up @@ -110,6 +120,9 @@ def merge(options)
ClientOptions.default.transparent_gzip_decompression = true
RequestOptions.default.retries = 0
RequestOptions.default.max_elapsed_time = 900
RequestOptions.default.base_interval = 1
RequestOptions.default.max_interval = 60
RequestOptions.default.multiplier = 2
RequestOptions.default.normalize_unicode = false
RequestOptions.default.skip_serialization = false
RequestOptions.default.skip_deserialization = false
Expand Down
5 changes: 3 additions & 2 deletions google-apis-core/spec/google/apis/core/http_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ class DecryptResponse
expect(Retriable).to receive(:retriable).with(
tries: Google::Apis::RequestOptions.default.retries + 1,
max_elapsed_time: Google::Apis::RequestOptions.default.max_elapsed_time,
base_interval: 1,
multiplier: 2,
base_interval: Google::Apis::RequestOptions.default.base_interval,
max_interval: Google::Apis::RequestOptions.default.max_interval,
multiplier: Google::Apis::RequestOptions.default.multiplier,
on: described_class::RETRIABLE_ERRORS).and_call_original
allow(Retriable).to receive(:retriable).and_call_original

Expand Down
3 changes: 3 additions & 0 deletions google-apis-core/spec/google/apis/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
it 'sets default values' do
expect(defaults.retries).to eq(5) # Overriden in spec_helper.rb
expect(defaults.max_elapsed_time).to eq(900)
expect(defaults.base_interval).to eq(1)
expect(defaults.max_interval).to eq(60)
expect(defaults.multiplier).to eq(2)
expect(defaults.normalize_unicode).to be false
expect(defaults.skip_serialization).to be false
expect(defaults.skip_deserialization).to be false
Expand Down

0 comments on commit c575049

Please sign in to comment.