Sha256: d6ccd565e6bfadb1ac5f657820ae0ef1b5651d89d44700325bac861a540f4fd0

Contents?: true

Size: 1.01 KB

Versions: 63

Compression:

Stored size: 1.01 KB

Contents

require 'aws-sdk'
require 'contracts'
require 'retries'

module Cloudstrap
  module Amazon
    module Support
      module RateLimitHandler
        include ::Contracts::Core
        include ::Contracts::Builtin

        Contract None => Proc
        def request_limit_exceeded_handler
          Proc.new do |exception, attempt, seconds|
            STDERR.puts "Encountered a #{exception.class}. DON'T PANIC. Waiting and trying again works (usually). Let's do that! (this was attempt #{attempt} after #{seconds} seconds)"
          end
        end

        Contract Symbol, Args[Any] => Any
        def call_api(method, *args)
          with_retries(
            rescue: [
              Aws::EC2::Errors::RequestLimitExceeded,
              Aws::Route53::Errors::ThrottlingException
            ],
            handler: request_limit_exceeded_handler,
            base_sleep_seconds: 1.0,
            max_sleep_seconds: 8.0
          ) do
            api.method(method).call(*args)
          end
        end
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
cloudstrap-0.40.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.39.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.18.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.17.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.5.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.3.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.2.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.38.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.9.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.6.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.5.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.4.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.37.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.35.5.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.35.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.34.5.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.34.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.34.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb