class RetryingS3Client

Constants

VERSION

Public Class Methods

new(s3, logger, options = {}) click to toggle source
# File lib/retrying_s3_client.rb, line 9
def initialize(s3, logger, options = {})
  @s3 = s3
  @logger = logger
  @sleeper = options[:sleeper] || Kernel.method(:sleep)
end
wrap(s3, logger, options) click to toggle source
# File lib/retrying_s3_client.rb, line 4
def self.wrap(s3, logger, options)
  return s3 if s3.is_a?(RetryingS3Client)
  new(s3, logger, options)
end

Public Instance Methods

method_missing(sym, *args, &block) click to toggle source
# File lib/retrying_s3_client.rb, line 15
def method_missing(sym, *args, &block)
  with_backoff { @s3.send(sym, *args, &block) }
end
with_backoff(backoff = 1) { || ... } click to toggle source
# File lib/retrying_s3_client.rb, line 19
def with_backoff(backoff = 1)
  yield
rescue Aws::S3::Errors::Http503Error
  @logger.error "Got Aws::S3::Errors::Http503Error, sleeping #{backoff}"
  @sleeper.call(backoff)
  @logger.info "Woke up after Aws::S3::Errors::Http503Error retrying again"
  backoff *= 2
  retry
end