Module: BlockRepeater::Replay
- Included in:
- BlockRepeater
- Defined in:
- lib/block_repeater/replay.rb
Overview
Provides a retry-with-refresh mechanism for UI actions that may fail due to transient driver/page errors.
Consumers configure which exceptions to catch and how to refresh the page.
Instance Method Summary collapse
-
#replay(exceptions:, times: 3, delay: 0.5, refresh: nil, logger: nil, &block) ⇒ Object
Execute a block, retrying on configured exceptions with optional page refresh.
Instance Method Details
#replay(exceptions:, times: 3, delay: 0.5, refresh: nil, logger: nil, &block) ⇒ Object
Execute a block, retrying on configured exceptions with optional page refresh.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/block_repeater/replay.rb', line 20 def replay(exceptions:, times: 3, delay: 0.5, refresh: nil, logger: nil, &block) raise ArgumentError, 'replay requires a block' unless block attempt = 0 repeat(times: times, delay: delay, &block).catch(exceptions: exceptions, behaviour: :continue) do |e| attempt += 1 logger&.error { e. } raise(e) if attempt >= times refresh&.call end.until do |result| !result.is_a?(Exception) end end |