Class: Tenax::Profile
- Inherits:
-
Object
- Object
- Tenax::Profile
- Defined in:
- lib/tenax/profile.rb
Overview
Per-profile configuration. Created via Configuration#profile.
Profiles are configured via a DSL block; methods serve double duty as setters (when called with arguments) and readers (when called without). This is the standard Ruby DSL convention.
Tenax.configure do |c|
c.profile :stripe do |p|
p.max_attempts 5 # set
p.backoff :exponential, base: 0.2, cap: 5
p.retry_on Net::ReadTimeout, IOError
end
end
Tenax.configuration.profile(:stripe).max_attempts # => 5 (read)
Once the configure block exits, the profile is frozen.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#backoff(strategy_or_symbol = UNSET) ⇒ Object
Get or set the backoff strategy.
-
#finalize! ⇒ Object
private
Freeze the profile, preventing further mutation.
-
#initialize(name) ⇒ Profile
constructor
A new instance of Profile.
-
#max_attempts(value = UNSET) ⇒ Integer, self
Get or set the maximum number of attempts.
-
#retry_on(*error_classes) ⇒ Object
Get or set the list of retryable error classes.
Constructor Details
#initialize(name) ⇒ Profile
Returns a new instance of Profile.
45 46 47 48 49 50 |
# File 'lib/tenax/profile.rb', line 45 def initialize(name) @name = name @max_attempts = DEFAULT_MAX_ATTEMPTS @backoff = Retry::Backoff::Exponential.new(base: 0.5, cap: 30.0) @retry_on_errors = [StandardError].freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
43 44 45 |
# File 'lib/tenax/profile.rb', line 43 def name @name end |
Instance Method Details
#backoff(strategy_or_symbol = UNSET) ⇒ Object
Get or set the backoff strategy. When called with no arguments, returns the current strategy. When called with arguments, sets it. Accepts a symbol referencing a built-in strategy or any object responding to #delay_for.
74 75 76 77 78 79 |
# File 'lib/tenax/profile.rb', line 74 def backoff(strategy_or_symbol = UNSET, **) return @backoff if strategy_or_symbol.equal?(UNSET) @backoff = build_backoff(strategy_or_symbol, **) self end |
#finalize! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Freeze the profile, preventing further mutation.
97 98 99 |
# File 'lib/tenax/profile.rb', line 97 def finalize! freeze end |
#max_attempts(value = UNSET) ⇒ Integer, self
Get or set the maximum number of attempts.
55 56 57 58 59 60 61 |
# File 'lib/tenax/profile.rb', line 55 def max_attempts(value = UNSET) return @max_attempts if value.equal?(UNSET) validate_max_attempts!(value) @max_attempts = value self end |
#retry_on(*error_classes) ⇒ Object
Get or set the list of retryable error classes. When called with no arguments, returns the current list. When called with arguments, replaces the list.
87 88 89 90 91 92 93 |
# File 'lib/tenax/profile.rb', line 87 def retry_on(*error_classes) return @retry_on_errors if error_classes.empty? && instance_variable_defined?(:@retry_on_errors) validate_retry_on!(error_classes) @retry_on_errors = error_classes.freeze self end |