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.51.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.50.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.12.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.11.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.10.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.8.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.4.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.2.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.49.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.48.15.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.48.2.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.48.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.47.8.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.47.7.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.47.2.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.47.0.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.46.7.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.46.4.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.46.3.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb