Module: Qurd::Mixins::AwsClients
- Included in:
- Action, Action, Listener, Qurd::Message, Processor
- Defined in:
- lib/qurd/mixins/aws_clients.rb
Overview
Generic method for instantiating Aws clients
Instance Method Summary collapse
-
#aws_client(client) ⇒ Object
Memoize Aws clients, the caller must respond to
region
andaws_credentials
. -
#aws_retryable(tries = 2) ⇒ Object
Wrap a block in a
begin
rescue
, which retries, ifAws::Errors::ServiceError
is raised.
Instance Method Details
#aws_client(client) ⇒ Object
Memoize Aws clients, the caller must respond to region
and aws_credentials
14 15 16 17 18 19 20 |
# File 'lib/qurd/mixins/aws_clients.rb', line 14 def aws_client(client) @qurd_aws_clients ||= {} klass = Object.const_get("Aws::#{client}::Client") @qurd_aws_clients[client.to_sym] ||= klass.new( region: region, credentials: aws_credentials) end |
#aws_retryable(tries = 2) ⇒ Object
Wrap a block in a begin
rescue
, which retries, if Aws::Errors::ServiceError
is raised. The method will retry the block immediately, up to n tries
.
27 28 29 30 31 32 33 34 |
# File 'lib/qurd/mixins/aws_clients.rb', line 27 def aws_retryable(tries = 2) tries = [1, tries.to_i].max begin yield rescue Aws::Errors::ServiceError => e (tries -= 1).zero? ? raise(e) : retry end end |