Class: Tlopo::Retry
- Inherits:
-
Object
- Object
- Tlopo::Retry
- Extended by:
- Setters
- Defined in:
- lib/tlopo/retry.rb,
lib/tlopo/retry/version.rb
Constant Summary collapse
- VERSION =
'0.2.1'
Instance Method Summary collapse
-
#initialize(**args) ⇒ Retry
constructor
A new instance of Retry.
- #run(&block) ⇒ Object
Methods included from Setters
Constructor Details
#initialize(**args) ⇒ Retry
Returns a new instance of Retry.
25 26 27 28 29 30 |
# File 'lib/tlopo/retry.rb', line 25 def initialize(**args) @tries = args[:tries] || 3 @interval = args[:interval] || 1 @exponential_backoff = args[:exponential_backoff] || false @error_types = args[:error_types] || [StandardError] end |
Instance Method Details
#run(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tlopo/retry.rb', line 32 def run(&block) count = 1 while count <= @tries next unless block_given? begin return instance_eval(&block) rescue *@error_types => e time = @exponential_backoff ? @interval**count : @interval sleep time count += 1 e end end LOGGER.error e raise "Retries exhausted, error: #{e.}" end |