Sha256: 5cd67395ade1a226a883001a76a2b6bd0815d80bf9b50899683efc7d2ee022cc

Contents?: true

Size: 949 Bytes

Versions: 8

Compression:

Stored size: 949 Bytes

Contents

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

module StackatoLKG
  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,
            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

8 entries across 8 versions & 1 rubygems

Version Path
cloudstrap-0.30.11.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.30.3.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.30.2.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.30.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.29.7.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.29.6.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.29.5.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb
cloudstrap-0.29.1.pre lib/cloudstrap/amazon/support/rate_limit_handler.rb