Module: Imap::Backup::RetryOnError
- Included in:
- Account::Folder, Client::AutomaticLoginWrapper
- Defined in:
- lib/imap/backup/retry_on_error.rb
Overview
Provides a mechanism for retrying blocks of code which often throw errors
Instance Method Summary collapse
-
#retry_on_error(errors:, limit: 10, on_error: nil, &block) ⇒ Object
Calls the supplied block, traps the given types of errors retrying up to a given number of times.
Instance Method Details
#retry_on_error(errors:, limit: 10, on_error: nil, &block) ⇒ Object
Calls the supplied block, traps the given types of errors retrying up to a given number of times
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imap/backup/retry_on_error.rb', line 16 def retry_on_error(errors:, limit: 10, on_error: nil, &block) tries ||= 1 block.call rescue *errors => e if tries < limit = "#{e}, attempt #{tries} of #{limit}" Logger.logger.debug on_error&.call tries += 1 retry end raise e end |