1.5.0 (latest) 1.4.1 1.3.0 1.2.0 1.1.0 1.0.1 0.26.0 0.25.0 0.24.0 Reference documentation and code samples for the gapic-common class Gapic::Common::RetryPolicy.

Gapic Common retry policy base class.


<br />

A policy distinguishes "set to this value" from "never set". Every setting is stored as `nil`
until someone supplies it, and the reader for each substitutes the corresponding `DEFAULT_`
constant on the way out, so a reader can never say which of the two happened. That distinction is
what lets [#apply_defaults](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy#Gapic__Common__RetryPolicy_apply_defaults_instance_ "Gapic::Common::RetryPolicy#apply_defaults (method)") fill in gaps without overwriting a caller's choices, and [#overrides](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy#Gapic__Common__RetryPolicy_overrides_instance_ "Gapic::Common::RetryPolicy#overrides (method)")
report what a caller actually asked for.

## Inherits

- Object

## Methods

### #call

    def call(error = nil) -> Boolean

**Aliases**

- [#perform_delay](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy#Gapic__Common__RetryPolicy_perform_delay_instance_)
Perform delay if and only if retriable.


<br />

If positional argument `error` is provided, the retriable logic uses
`retry_codes`. Otherwise, `timeout` is used.
**Returns**

- (Boolean) --- Whether the delay was executed.

### #delay

    def delay() -> Numeric

Current delay value in seconds.
**Returns**

- (Numeric) --- Time delay in seconds.

### #dup

    def dup() -> RetryPolicy

Returns a duplicate in a non-executing state, i.e. with the deadline
and current delay reset.
**Returns**

- ([RetryPolicy](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy))

### #initial_delay

    def initial_delay() -> Numeric

**Returns**

- (Numeric) --- Initial delay in seconds.

### #initialize

    def initialize(initial_delay: nil, max_delay: nil, multiplier: nil, retry_codes: nil, timeout: nil, jitter: nil, retry_predicate: nil) -> RetryPolicy

Create new Gapic::Common::RetryPolicy instance.
**Parameters**

- **initial_delay** (Numeric) *(defaults to: nil)* --- Initial delay in seconds.
- **max_delay** (Numeric) *(defaults to: nil)* --- Maximum delay in seconds.
- **multiplier** (Numeric) *(defaults to: nil)* --- The delay scaling factor for each subsequent retry attempt.
- **retry_codes** (Array\<String\|Integer\>) *(defaults to: nil)* --- List of retry codes.
- **timeout** (Numeric) *(defaults to: nil)* --- Timeout threshold value in seconds.
- **jitter** (Numeric) *(defaults to: nil)* --- Random jitter added to the delay in seconds.
- **retry_predicate** (Proc, nil) *(defaults to: nil)* --- The predicate to evaluate whether to retry on a given error. Optional. If the predicate is specified, it is run first. If it returns nil, the decision on whether to retry is made on the basis of retry_codes. Otherwise, the truthiness of the return value determines whether to retry.
**Returns**

- ([RetryPolicy](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy)) --- a new instance of RetryPolicy
**Raises**

- (ArgumentError)

### #jitter

    def jitter() -> Numeric

**Returns**

- (Numeric) --- Random jitter added to the delay in seconds.

### #max_delay

    def max_delay() -> Numeric

**Returns**

- (Numeric) --- Maximum delay in seconds.

### #multiplier

    def multiplier() -> Numeric

**Returns**

- (Numeric) --- The delay scaling factor for each subsequent retry attempt.

### #perform_delay

    def perform_delay(error = nil) -> Boolean

**Alias Of** : [#call](https://docs.cloud.google.com/ruby/docs/reference/gapic-common/latest/Gapic-Common-RetryPolicy#Gapic__Common__RetryPolicy_call_instance_) Perform delay if and only if retriable.


<br />

If positional argument `error` is provided, the retriable logic uses
`retry_codes`. Otherwise, `timeout` is used.
**Returns**

- (Boolean) --- Whether the delay was executed.

### #perform_delay!

    def perform_delay!() -> Boolean

Perform delay.
**Returns**

- (Boolean) --- Whether the delay was executed.

### #perform_delay_count

    def perform_delay_count() -> Integer

Current number of times the delay has been performed
**Returns**

- (Integer)

### #retry_codes

    def retry_codes() -> Array<Integer>

**Returns**

- (Array\<Integer\>) --- List of retry codes.

### #retry_predicate

    def retry_predicate() -> Proc, nil

The predicate to evaluate whether to retry on a given error. Optional.

When a predicate is specified:

1. The predicate is executed first on the error.
2. If it returns nil, the decision on whether to retry is made on the basis of retry_codes.
3. Otherwise, the truthiness of the return value determines whether to retry.
**Returns**

- (Proc, nil)

### #start!

    def start!(mock_delay: false)

Start tracking the deadline and delay by initializing those values.


<br />

This is normally done when the object is constructed, but it can be
done explicitly in order to reinitialize the state in case this
retry policy was created in the past or is being reused.
**Parameter**

- **mock_delay** (boolean, Proc) *(defaults to: false)* --- if truthy, delays are "mocked", meaning they do not actually take time, but are measured as if they did, which is useful for tests. If set to a Proc, it will be called whenever a delay would happen, and passed the delay in seconds, also useful for testing.

### #timeout

    def timeout() -> Numeric

**Returns**

- (Numeric) --- Timeout threshold value in seconds.

## Constants

### DEFAULT_INITIAL_DELAY

**value:**1

### DEFAULT_MAX_DELAY

**value:**15

### DEFAULT_MULTIPLIER

**value:**1.3

### DEFAULT_RETRY_CODES

**value:**\[\].freeze

### DEFAULT_TIMEOUT

**value:**3600