Module: Nvoi::Utils::Retry
- Defined in:
- lib/nvoi/utils/retry.rb
Overview
Retry helper module for simple retry scenarios
Class Method Summary collapse
-
.poll(max_attempts: 30, interval: 2) ⇒ Object
Poll until condition is met or timeout Returns the result of the block, or nil if timeout.
-
.poll!(max_attempts: 30, interval: 2, error_message: "operation timed out") ⇒ Object
Poll with error on timeout.
- .with_retry(max_attempts: 3, log: nil) ⇒ Object
Class Method Details
.poll(max_attempts: 30, interval: 2) ⇒ Object
Poll until condition is met or timeout Returns the result of the block, or nil if timeout
68 69 70 71 72 73 74 75 76 |
# File 'lib/nvoi/utils/retry.rb', line 68 def self.poll(max_attempts: 30, interval: 2) max_attempts.times do result = yield return result if result sleep(interval) end nil end |
.poll!(max_attempts: 30, interval: 2, error_message: "operation timed out") ⇒ Object
Poll with error on timeout
79 80 81 82 83 84 |
# File 'lib/nvoi/utils/retry.rb', line 79 def self.poll!(max_attempts: 30, interval: 2, error_message: "operation timed out") result = poll(max_attempts:, interval:) { yield } raise Errors::TimeoutError, unless result result end |
.with_retry(max_attempts: 3, log: nil) ⇒ Object
61 62 63 64 |
# File 'lib/nvoi/utils/retry.rb', line 61 def self.with_retry(max_attempts: 3, log: nil) executor = StepExecutor.new(max_attempts, log) executor.execute("operation") { yield } end |