Class: Patiently::Configuration
- Inherits:
-
Object
- Object
- Patiently::Configuration
- Defined in:
- lib/patiently/configuration.rb
Overview
Holds the global defaults for Helpers#patiently. Access the
shared instance via Patiently.config.
Constant Summary collapse
- DEFAULT_TIMEOUT =
5- DEFAULT_RETRY_INTERVALS =
[0.05].freeze
- DEFAULT_MIN_RETRIES =
1- DEFAULT_MAX_RETRIES =
nil = unlimited
nil
Instance Attribute Summary collapse
-
#max_retries ⇒ Object
The maximum number of retries
patientlyperforms before giving up, regardless of the timeout. -
#min_retries ⇒ Object
The minimum number of retries (re-invocations after the first call)
patientlyperforms before it is allowed to give up, even if the timeout has already elapsed. -
#retry_intervals ⇒ Object
An array of sleep durations (in seconds) used between retries.
-
#timeout ⇒ Object
How long (in seconds)
patientlykeeps retrying before giving up.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#reset! ⇒ Object
Restores all defaults.
-
#retry_interval(retry_index) ⇒ Object
Returns the sleep duration for the given (zero-based) retry index.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 |
# File 'lib/patiently/configuration.rb', line 14 def initialize reset! end |
Instance Attribute Details
#max_retries ⇒ Object
The maximum number of retries patiently performs before giving up,
regardless of the timeout. nil means unlimited.
43 44 45 |
# File 'lib/patiently/configuration.rb', line 43 def max_retries @max_retries end |
#min_retries ⇒ Object
The minimum number of retries (re-invocations after the first call)
patiently performs before it is allowed to give up, even if the timeout
has already elapsed. 1 reproduces the historical "try at least twice"
behavior.
37 38 39 |
# File 'lib/patiently/configuration.rb', line 37 def min_retries @min_retries.nil? ? DEFAULT_MIN_RETRIES : @min_retries end |
#retry_intervals ⇒ Object
An array of sleep durations (in seconds) used between retries. The value
at index N is used before the (N+1)-th retry; once the array is exhausted
its last element is reused for all further retries. This allows a backoff,
e.g. [0.05, 0.05, 0.05, 0.1]. A bare number is accepted and wrapped in
an array.
28 29 30 31 |
# File 'lib/patiently/configuration.rb', line 28 def retry_intervals intervals = @retry_intervals.nil? ? DEFAULT_RETRY_INTERVALS : @retry_intervals Array(intervals) end |
#timeout ⇒ Object
How long (in seconds) patiently keeps retrying before giving up.
19 20 21 |
# File 'lib/patiently/configuration.rb', line 19 def timeout @timeout.nil? ? DEFAULT_TIMEOUT : @timeout end |
Instance Method Details
#reset! ⇒ Object
Restores all defaults. Handy in test suites.
54 55 56 57 58 59 |
# File 'lib/patiently/configuration.rb', line 54 def reset! @timeout = nil @retry_intervals = nil @min_retries = nil @max_retries = nil end |
#retry_interval(retry_index) ⇒ Object
Returns the sleep duration for the given (zero-based) retry index.
48 49 50 51 |
# File 'lib/patiently/configuration.rb', line 48 def retry_interval(retry_index) intervals = retry_intervals intervals[retry_index] || intervals.last end |