Module: Imap::Backup::RetryOnError

Included in:
Account::Folder, Client::AutomaticLoginWrapper
Defined in:
lib/imap/backup/retry_on_error.rb

Instance Method Summary collapse

Instance Method Details

#retry_on_error(errors:, limit: 10, on_error: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/imap/backup/retry_on_error.rb', line 7

def retry_on_error(errors:, limit: 10, on_error: nil)
  tries ||= 1
  yield
rescue *errors => e
  if tries < limit
    message = "#{e}, attempt #{tries} of #{limit}"
    Logger.logger.debug message
    on_error&.call
    tries += 1
    retry
  end
  raise e
end