sqewer 6.5.1 → 8.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf1c2d6717fda50ce8a72721d00ffcfd2fae867f40f40a07a0cf48cbe94fe17b
4
- data.tar.gz: fb1622a03a4f540aaa96d24dc3d5d39c5d400b658f371c88dc682844ac784ea5
3
+ metadata.gz: c3bde02330a40856f767370e8098ec7e11216c1434977b8072cdd78af410d132
4
+ data.tar.gz: 79a8fae95732af97fee2faa101abe058015e542fafe00c6f193298a8d2a9db29
5
5
  SHA512:
6
- metadata.gz: fd4e73838959531d646d0ed69fd8316e85075d3abe96b5362c58ff5de9af27b26cec142273bce674aaadf571275f1f91cf055c305be4b9797edd75eb89b74222
7
- data.tar.gz: 9f4b9006f504bd4a0a85abea9d3c82bf2c70ccdfecf59095df58a1e6b1b8b3ed0b6ba819778f828c48e5dd1865c1f312c5feda78485e9ceab95565e9559cc870
6
+ metadata.gz: d0ee92f90995e1ad4fc439da92550fb6e9a9a294941b444a41b761e5589d82fb4cc4e5d7252359bc5b22f5675d6dcfb7f4dfb1fcf81e7376e3939f6a7e6cccd2
7
+ data.tar.gz: f95b7659f1fa00b51a0f4882515b5f0c6d655148849de83b9da4bf104814ccfe0a192cf617c1a56a2c154c8f79331ee5e6acb6979f7d795fc68ee4fc3401f831
data/.travis.yml CHANGED
@@ -1,11 +1,7 @@
1
1
  gemfile:
2
- - gemfiles/Gemfile.rails-4.2.x
3
2
  - gemfiles/Gemfile.rails-5.0.x
4
3
  - gemfiles/Gemfile.rails-5.1.x
5
4
  rvm:
6
- - 2.3.7
7
- - 2.4.5
8
- - 2.5.1
9
5
  - 2.6.5
10
6
  - 2.7.0
11
7
  cache: bundler
@@ -13,15 +9,3 @@ sudo: false
13
9
  env:
14
10
  global:
15
11
  - AWS_REGION=eu-central-1
16
- matrix:
17
- exclude:
18
- - rvm: 2.3.7
19
- gemfile: gemfiles/Gemfile.rails-5.0.x
20
- - rvm: 2.3.7
21
- gemfile: gemfiles/Gemfile.rails-5.1.x
22
- - rvm: 2.5.1
23
- gemfile: gemfiles/Gemfile.rails-4.2.x
24
- - rvm: 2.6.5
25
- gemfile: gemfiles/Gemfile.rails-4.2.x
26
- - rvm: 2.7.0
27
- gemfile: gemfiles/Gemfile.rails-4.2.x
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### 8.0.2
2
+ - Add `Aws::SQS::Errors::AccessDenied` to the list of errors that Sqewer must release the singleton SQS client
3
+
4
+ ### 8.0.1
5
+ - Release the singleton SQS client when AWS raises credentials error to be able to use a new credential next time
6
+
7
+ ### 8.0.0
8
+ - Remove method `Sqewer.client=`
9
+ - Change `Sqewer::Connection` to use a singleton SQS client by default
10
+
11
+ ### 7.0.0
12
+ - Remove support of Ruby 2.3, 2.4 and 2.5
13
+ - Remove support of Rails 4
14
+ - Change `Sqewer::Connection` to preferentially use a singleton instance of `Aws::SQS::Client`, which can be set using `Sqewer.client=`. This avoids many HTTP requests to the AWS metadata endpoint when getting credentials.
15
+
1
16
  ### 6.5.1
2
17
  - Also retry on `Aws::SQS::Errors::InternalError` exception when receiving/sending messages. This will make
3
18
  the receiving thread more resilient to sudden SQS failures. By the time SQS recovers the receiving thread
data/README.md CHANGED
@@ -48,7 +48,7 @@ The messages will only be deleted from SQS once the job execution completes with
48
48
 
49
49
  ## Requirements
50
50
 
51
- Ruby 2.1+, version 2 of the AWS SDK. You can also run Sqewer backed by a SQLite database file, which can be handy for development situations.
51
+ Ruby 2.6+, version 2 of the AWS SDK. You can also run Sqewer backed by a SQLite database file, which can be handy for development situations.
52
52
 
53
53
  ## Job storage
54
54
 
@@ -288,7 +288,7 @@ and traceable (make good use of logging).
288
288
 
289
289
  # Usage with Rails via ActiveJob
290
290
 
291
- This gem includes a queue adapter for usage with ActiveJob in Rails 4.2+. The functionality
291
+ This gem includes a queue adapter for usage with ActiveJob in Rails 5+. The functionality
292
292
  is well-tested and should function for any well-conforming ActiveJob subclasses.
293
293
 
294
294
  To run the default `sqewer` worker setup against your Rails application, first set it as the
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sqewer"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/lib/sqewer.rb CHANGED
@@ -11,6 +11,11 @@ module Sqewer
11
11
  end
12
12
  end
13
13
 
14
+ # Returns a singleton of Aws::SQS::Client
15
+ def self.client
16
+ Sqewer::Connection.client
17
+ end
18
+
14
19
  # Loads a particular Sqewer extension that is not loaded
15
20
  # automatically during the gem require.
16
21
  #
@@ -13,6 +13,11 @@ class Sqewer::Connection
13
13
 
14
14
  NotOurFaultAwsError = Class.new(Sqewer::Error)
15
15
 
16
+ SQS_ERRORS_TO_RELEASE_CLIENT = [
17
+ Aws::Errors::MissingCredentialsError,
18
+ Aws::SQS::Errors::AccessDenied,
19
+ ]
20
+
16
21
  # A wrapper for most important properties of the received message
17
22
  class Message < Struct.new(:receipt_handle, :body, :attributes)
18
23
  def inspect
@@ -39,12 +44,25 @@ class Sqewer::Connection
39
44
  raise "SQS_QUEUE_URL not set in the environment. This is the queue URL Sqewer uses by default."
40
45
  end
41
46
 
47
+ # Returns a singleton of Aws::SQS::Client
48
+ def self.client
49
+ # It's better using a singleton client to prevent making a lot of HTTP
50
+ # requests to the AWS metadata endpoint when getting credentials.
51
+ @client ||= begin
52
+ require 'aws-sdk-sqs'
53
+ ::Aws::SQS::Client.new(
54
+ instance_profile_credentials_timeout: 1,
55
+ instance_profile_credentials_retries: 5,
56
+ )
57
+ end
58
+ end
59
+
42
60
  # Initializes a new adapter, with access to the SQS queue at the given URL.
43
61
  #
44
62
  # @param queue_url[String] the SQS queue URL (the URL can be copied from your AWS console)
45
- def initialize(queue_url)
46
- require 'aws-sdk-sqs'
63
+ def initialize(queue_url, client: self.class.client)
47
64
  @queue_url = queue_url
65
+ @client = client
48
66
  end
49
67
 
50
68
  # Receive at most 10 messages from the queue, and return the array of Message objects. Retries for at
@@ -55,7 +73,7 @@ class Sqewer::Connection
55
73
  # @return [Array<Message>] an array of Message objects
56
74
  def receive_messages
57
75
  Retriable.retriable on: network_and_aws_sdk_errors, tries: MAX_RANDOM_RECEIVE_FAILURES do
58
- response = client.receive_message(
76
+ response = @client.receive_message(
59
77
  queue_url: @queue_url,
60
78
  attribute_names: ['All'],
61
79
  wait_time_seconds: DEFAULT_TIMEOUT_SECONDS,
@@ -63,6 +81,14 @@ class Sqewer::Connection
63
81
  )
64
82
  response.messages.map {|message| Message.new(message.receipt_handle, message.body, message.attributes) }
65
83
  end
84
+ rescue *SQS_ERRORS_TO_RELEASE_CLIENT
85
+ # We noticed cases where errors related to AWS credentials started to happen suddenly.
86
+ # We don't know the root cause yet, but what we can do is release the
87
+ # singleton @client instance because it contains a cache of credentials that in most
88
+ # cases is no longer valid.
89
+ self.class.release_client
90
+
91
+ raise
66
92
  end
67
93
 
68
94
  # Send a message to the backing queue
@@ -189,6 +215,12 @@ class Sqewer::Connection
189
215
  buffer.each_batch {|batch| handle_batch_with_retries(:delete_message_batch, batch) }
190
216
  end
191
217
 
218
+ protected
219
+
220
+ def self.release_client
221
+ @client = nil
222
+ end
223
+
192
224
  private
193
225
 
194
226
  def network_and_aws_sdk_errors
@@ -197,7 +229,7 @@ class Sqewer::Connection
197
229
 
198
230
  def handle_batch_with_retries(method, batch)
199
231
  Retriable.retriable on: network_and_aws_sdk_errors, tries: MAX_RANDOM_FAILURES_PER_CALL do
200
- resp = client.send(method, queue_url: @queue_url, entries: batch)
232
+ resp = @client.send(method, queue_url: @queue_url, entries: batch)
201
233
  wrong_messages, aws_failures = resp.failed.partition {|m| m.sender_fault }
202
234
  if wrong_messages.any?
203
235
  err = wrong_messages.inspect + ', ' + resp.inspect
@@ -208,12 +240,13 @@ class Sqewer::Connection
208
240
  raise NotOurFaultAwsError
209
241
  end
210
242
  end
211
- end
212
-
213
- def client
214
- @client ||= Aws::SQS::Client.new(
215
- instance_profile_credentials_timeout: 1, # defaults to 1 second
216
- instance_profile_credentials_retries: 5, # defaults to 0 retries
217
- )
243
+ rescue *SQS_ERRORS_TO_RELEASE_CLIENT
244
+ # We noticed cases where errors related to AWS credentials started to happen suddenly.
245
+ # We don't know the root cause yet, but what we can do is release the
246
+ # singleton @client instance because it contains a cache of credentials that in most
247
+ # cases is no longer valid.
248
+ self.class.release_client
249
+
250
+ raise
218
251
  end
219
252
  end
@@ -1,3 +1,3 @@
1
1
  module Sqewer
2
- VERSION = '6.5.1'
2
+ VERSION = '8.0.2'
3
3
  end
data/sqewer.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{Process jobs from SQS}
13
13
  spec.description = %q{A full-featured library for all them SQS worker needs}
14
14
  spec.homepage = "https://github.com/WeTransfer/sqewer"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -49,4 +50,5 @@ Gem::Specification.new do |spec|
49
50
  spec.add_development_dependency "dotenv"
50
51
  spec.add_development_dependency "simplecov"
51
52
  spec.add_development_dependency "appsignal", '~> 2'
53
+ spec.add_development_dependency "pry-byebug"
52
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.5.1
4
+ version: 8.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-18 00:00:00.000000000 Z
12
+ date: 2021-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-sqs
@@ -221,11 +221,26 @@ dependencies:
221
221
  - - "~>"
222
222
  - !ruby/object:Gem::Version
223
223
  version: '2'
224
+ - !ruby/object:Gem::Dependency
225
+ name: pry-byebug
226
+ requirement: !ruby/object:Gem::Requirement
227
+ requirements:
228
+ - - ">="
229
+ - !ruby/object:Gem::Version
230
+ version: '0'
231
+ type: :development
232
+ prerelease: false
233
+ version_requirements: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
224
238
  description: A full-featured library for all them SQS worker needs
225
239
  email:
226
240
  - me@julik.nl
227
241
  - linkyndy@gmail.com
228
242
  executables:
243
+ - console
229
244
  - sqewer
230
245
  - sqewer_rails
231
246
  extensions: []
@@ -239,10 +254,10 @@ files:
239
254
  - Gemfile
240
255
  - README.md
241
256
  - Rakefile
257
+ - bin/console
242
258
  - bin/sqewer
243
259
  - bin/sqewer_rails
244
260
  - example.env
245
- - gemfiles/Gemfile.rails-4.2.x
246
261
  - gemfiles/Gemfile.rails-5.0.x
247
262
  - gemfiles/Gemfile.rails-5.1.x
248
263
  - lib/sqewer.rb
@@ -278,14 +293,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
293
  requirements:
279
294
  - - ">="
280
295
  - !ruby/object:Gem::Version
281
- version: '0'
296
+ version: 2.6.0
282
297
  required_rubygems_version: !ruby/object:Gem::Requirement
283
298
  requirements:
284
299
  - - ">="
285
300
  - !ruby/object:Gem::Version
286
301
  version: '0'
287
302
  requirements: []
288
- rubygems_version: 3.0.6
303
+ rubygems_version: 3.1.6
289
304
  signing_key:
290
305
  specification_version: 4
291
306
  summary: Process jobs from SQS
@@ -1,8 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Gemspec as base dependency set
4
- gemspec path: __dir__ + '/..'
5
-
6
- gem 'sqlite3', '~> 1.3.6'
7
- gem 'activejob', "~> 4.2.0"
8
- gem 'activerecord', "~> 4.2.0"