Class: Baidubce::BackOffRetryPolicy
- Inherits:
-
Object
- Object
- Baidubce::BackOffRetryPolicy
- Includes:
- Log
- Defined in:
- lib/baidubce/retry_policy.rb
Overview
When a maximum of delay time is specified, the delay time will never exceed this limit.
Constant Summary
Constants included from Log
Log::DEFAULT_LOG_FILE, Log::LOG_FILE_SIZE, Log::MAX_NUM_LOG
Instance Attribute Summary collapse
-
#base_interval_in_millis ⇒ Object
Returns the value of attribute base_interval_in_millis.
-
#max_delay_in_millis ⇒ Object
Returns the value of attribute max_delay_in_millis.
-
#max_error_retry ⇒ Object
Returns the value of attribute max_error_retry.
Instance Method Summary collapse
-
#get_delay_before_next_retry_in_millis(retries_attempted) ⇒ Object
Returns the delay time in milliseconds before the next retry.
-
#initialize(max_error_retry = 3, max_delay_in_millis = 20 * 1000, base_interval_in_millis = 300) ⇒ BackOffRetryPolicy
constructor
A new instance of BackOffRetryPolicy.
-
#should_retry(http_code, retries_attempted) ⇒ Object
Return true if the http client should retry the request.
Methods included from Log
#logger, set_log_file, set_log_level
Constructor Details
#initialize(max_error_retry = 3, max_delay_in_millis = 20 * 1000, base_interval_in_millis = 300) ⇒ BackOffRetryPolicy
Returns a new instance of BackOffRetryPolicy.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/baidubce/retry_policy.rb', line 46 def initialize(max_error_retry=3, max_delay_in_millis=20 * 1000, base_interval_in_millis=300) max_error_retry_msg = "max_error_retry should be a non-negative integer." max_delay_in_millis_msg = "max_delay_in_millis should be a non-negative integer." raise BceClientException.new(max_error_retry_msg) if max_error_retry < 0 raise BceClientException.new(max_delay_in_millis_msg) if max_delay_in_millis < 0 @max_error_retry = max_error_retry @max_delay_in_millis = max_delay_in_millis @base_interval_in_millis = base_interval_in_millis end |
Instance Attribute Details
#base_interval_in_millis ⇒ Object
Returns the value of attribute base_interval_in_millis.
44 45 46 |
# File 'lib/baidubce/retry_policy.rb', line 44 def base_interval_in_millis @base_interval_in_millis end |
#max_delay_in_millis ⇒ Object
Returns the value of attribute max_delay_in_millis.
44 45 46 |
# File 'lib/baidubce/retry_policy.rb', line 44 def max_delay_in_millis @max_delay_in_millis end |
#max_error_retry ⇒ Object
Returns the value of attribute max_error_retry.
44 45 46 |
# File 'lib/baidubce/retry_policy.rb', line 44 def max_error_retry @max_error_retry end |
Instance Method Details
#get_delay_before_next_retry_in_millis(retries_attempted) ⇒ Object
Returns the delay time in milliseconds before the next retry.
79 80 81 82 83 84 |
# File 'lib/baidubce/retry_policy.rb', line 79 def get_delay_before_next_retry_in_millis(retries_attempted) return 0 if retries_attempted < 0 delay_in_millis = (1 << retries_attempted) * @base_interval_in_millis return @max_delay_in_millis if delay_in_millis > @max_delay_in_millis return delay_in_millis end |
#should_retry(http_code, retries_attempted) ⇒ Object
Return true if the http client should retry the request.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/baidubce/retry_policy.rb', line 60 def should_retry(http_code, retries_attempted) # stop retrying when the maximum number of retries is reached return false if retries_attempted >= @max_error_retry return true if http_code.nil? # Only retry on a subset of service exceptions if http_code == 408 logger.debug('Retry for request timeout.') return true end if http_code >= 500 && http_code != 501 logger.debug('Retry for server error.') return true end return false end |