lib/sqewer/connection.rb in sqewer-8.0.2 vs lib/sqewer/connection.rb in sqewer-8.0.3
- old
+ new
@@ -11,15 +11,10 @@
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
@@ -79,11 +74,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 *SQS_ERRORS_TO_RELEASE_CLIENT
+ 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
@@ -238,15 +233,22 @@
# 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 *SQS_ERRORS_TO_RELEASE_CLIENT
+ 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
raise
+ end
+
+ def sqs_errors_to_release_client
+ [
+ Aws::Errors::MissingCredentialsError,
+ Aws::SQS::Errors::AccessDenied,
+ ]
end
end