lib/sqewer/connection.rb in sqewer-8.0.1 vs lib/sqewer/connection.rb in sqewer-8.0.2
- old
+ new
@@ -11,10 +11,15 @@
MAX_RANDOM_FAILURES_PER_CALL = 10
MAX_RANDOM_RECEIVE_FAILURES = 100 # sure to hit the max_elapsed_time of 900 seconds
NotOurFaultAwsError = Class.new(Sqewer::Error)
+ SQS_ERRORS_TO_RELEASE_CLIENT = [
+ Aws::Errors::MissingCredentialsError,
+ Aws::SQS::Errors::AccessDenied,
+ ]
+
# A wrapper for most important properties of the received message
class Message < Struct.new(:receipt_handle, :body, :attributes)
def inspect
body.inspect
end
@@ -74,11 +79,11 @@
wait_time_seconds: DEFAULT_TIMEOUT_SECONDS,
max_number_of_messages: BATCH_RECEIVE_SIZE
)
response.messages.map {|message| Message.new(message.receipt_handle, message.body, message.attributes) }
end
- rescue Aws::Errors::MissingCredentialsError
+ rescue *SQS_ERRORS_TO_RELEASE_CLIENT
# We noticed cases where errors related to AWS credentials started to happen suddenly.
# We don't know the root cause yet, but what we can do is release the
# singleton @client instance because it contains a cache of credentials that in most
# cases is no longer valid.
self.class.release_client
@@ -233,10 +238,10 @@
# We set the 'batch' param to an array with only the failed messages so only those get retried
batch = aws_failures.map {|aws_response_message| batch.find { |m| aws_response_message.id.to_s == m[:id] }}
raise NotOurFaultAwsError
end
end
- rescue Aws::Errors::MissingCredentialsError
+ rescue *SQS_ERRORS_TO_RELEASE_CLIENT
# We noticed cases where errors related to AWS credentials started to happen suddenly.
# We don't know the root cause yet, but what we can do is release the
# singleton @client instance because it contains a cache of credentials that in most
# cases is no longer valid.
self.class.release_client