Module: OCI::Retry
- Defined in:
- lib/oci/retry/retry.rb,
lib/oci/retry/retry_config.rb,
lib/oci/retry/functions/sleep.rb,
lib/oci/retry/internal/retry_state.rb,
lib/oci/retry/functions/should_retry_on_error.rb
Overview
Module for retry strategies for use with the SDK when calling OCI services
Defined Under Namespace
Modules: Functions, Internal Classes: RetryConfig
Class Method Summary collapse
-
.generate_opc_retry_token(token_length = 32) ⇒ String
Generates a token which can be used as a value for the opc-retry-token header value.
-
.make_retrying_call(retry_config, call_name: nil) ⇒ Object
Takes a block and then executes it with retries based on the provided configuration.
Class Method Details
.generate_opc_retry_token(token_length = 32) ⇒ String
Generates a token which can be used as a value for the opc-retry-token header value. The token will consist of uppercase letters (A-Z), lowercase letters (a-z) and digits (0-9)
61 62 63 64 65 66 67 68 69 |
# File 'lib/oci/retry/retry.rb', line 61 def self.generate_opc_retry_token(token_length = 32) raise 'The token must be at least one character long' if token_length.nil? || token_length < 1 available_chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a retry_token = '' token_length.times { retry_token << available_chars[rand(available_chars.size)] } retry_token end |
.make_retrying_call(retry_config, call_name: nil) ⇒ Object
Takes a block and then executes it with retries based on the provided configuration.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/oci/retry/retry.rb', line 19 def self.(retry_config, call_name: nil) raise 'A block must be provided' unless block_given? # If no retry configuration has been given, just do a single call return yield if retry_config.nil? retry_state = OCI::Retry::Internal::RetryState.new retry_state.start loop do begin OCI.logger.debug("[RETRYING_CALL] #{call_name}") if OCI.logger return yield rescue => e # rubocop:disable Style/RescueStandardError retry_state.increment_attempts retry_state.last_exception = e if retry_config.should_retry?(retry_state) if OCI.logger OCI.logger.debug( "[RETRYING] #{call_name} failed. Sleeping then retrying. Retry state: #{retry_state}" ) end retry_config.do_sleep(retry_state) else if OCI.logger OCI.logger.debug( "[RETRIES_EXHAUSTED] #{call_name} failed and exhausted retries. Retry state: #{retry_state}" ) end raise end end end end |