Class: Retriable::Config
- Inherits:
-
Object
- Object
- Retriable::Config
- Includes:
- Validation
- Defined in:
- lib/retriable/config.rb
Constant Summary collapse
- ATTRIBUTES =
(ExponentialBackoff::ATTRIBUTES + %i[ sleep_disabled max_elapsed_time intervals on retry_if on_retry on_give_up contexts ]).freeze
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
- #to_h ⇒ Object
- #validate! ⇒ Object
Methods included from Validation
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
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 |
# File 'lib/retriable/config.rb', line 26 def initialize(opts = {}) defaults = ExponentialBackoff::DEFAULTS @tries = defaults[:tries] @base_interval = defaults[:base_interval] @max_interval = defaults[:max_interval] @rand_factor = defaults[:rand_factor] @multiplier = defaults[:multiplier] @sleep_disabled = false @max_elapsed_time = 900 # 15 min @intervals = nil @on = [StandardError] @retry_if = nil @on_retry = nil @on_give_up = nil @contexts = {} opts.each do |k, v| raise ArgumentError, "#{k} is not a valid option" if !ATTRIBUTES.include?(k) instance_variable_set(:"@#{k}", v) end validate! end |
Instance Method Details
#to_h ⇒ Object
52 53 54 |
# File 'lib/retriable/config.rb', line 52 def to_h ATTRIBUTES.to_h { |key| [key, public_send(key)] } end |
#validate! ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/retriable/config.rb', line 56 def validate! validate_contexts validate_callable(:retry_if, retry_if) validate_callable(:on_retry, on_retry) validate_callable(:on_give_up, on_give_up) validate_on(on) validate_intervals if unbounded_tries?(tries) validate_unbounded_tries else validate_optional_non_negative_number(:max_elapsed_time, max_elapsed_time) return if intervals validate_positive_integer(:tries, tries) end end |