shoryuken 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca967b0796d5e97753b9d201edd7aaad2e1d5c44
4
- data.tar.gz: 4984a4ee2243ba5d8b42bec2e0c0b68e15b92c9f
3
+ metadata.gz: 1f28614380213b13c17dea0f85aae332f8e335f6
4
+ data.tar.gz: 34e084982c8aa8ec9b0306f04f548cc1321eec13
5
5
  SHA512:
6
- metadata.gz: 8143c4a34706093177109f9d822afc711c8c88cd51c2a64653e15b8054794327e59951fccbc5990992b7d568db3cd79a1e23a1a7ec33d7a7c29837e10534f187
7
- data.tar.gz: 5925db2ddbd791708c59b05a59805ca711bb82c9ef059db849568f8de9fec1619d7b52eab26cced9bb7b7e713ffd11227292c4294bbf642a49e60c35096fcb5d
6
+ metadata.gz: 40a160284600447798e3e1ebc61ec1e8bf596b0aa9d5558301d7f647e1ab1af285b845a9ec052eb52e157714d4066d3888f6f2192762898d9fc52decf1503a3b
7
+ data.tar.gz: 7f3d7584167804ad724dc3ca3a661cef8a4a60cadccebe333ceacb10333c0eb1bc7db9247439ddce875a1b7cb771769e9516afcda0ae5703991db780acd165d3
data/.rubocop.yml CHANGED
@@ -32,7 +32,7 @@ Style/Alias:
32
32
  Style/PerlBackrefs:
33
33
  Enabled: false
34
34
 
35
- Style/TrailingBlankLines:
35
+ Layout/TrailingBlankLines:
36
36
  Enabled: false
37
37
 
38
38
  # Override the HoundCI custom rules (they do not use Rubocop defaults)
@@ -42,7 +42,7 @@ Style/StringLiterals:
42
42
  Style/StringLiteralsInInterpolation:
43
43
  EnforcedStyle: single_quotes
44
44
 
45
- Style/ExtraSpacing:
45
+ Layout/ExtraSpacing:
46
46
  # disabling that in favour of using:
47
47
  # long_field_test_1 = 1
48
48
  # field_test_2 = 2
@@ -67,7 +67,7 @@ Style/ClassAndModuleChildren:
67
67
  Style/CommentAnnotation:
68
68
  Enabled: false
69
69
 
70
- Style/DotPosition:
70
+ Layout/DotPosition:
71
71
  EnforcedStyle: leading
72
72
 
73
73
  Style/GuardClause:
@@ -103,7 +103,7 @@ Style/RescueModifier:
103
103
  Style/ColonMethodCall:
104
104
  Enabled: false
105
105
 
106
- Style/FileName:
106
+ Naming/FileName:
107
107
  Enabled: false
108
108
 
109
109
  Style/FrozenStringLiteralComment:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [v4.0.1] - 2018-11-21
2
+
3
+ - Allow caching visibility_timeout lookups
4
+ - [#533](https://github.com/phstc/shoryuken/pull/533)
5
+
6
+ - Add queue name to inline executor
7
+ - [#532](https://github.com/phstc/shoryuken/pull/532)
8
+
1
9
  ## [v4.0.0] - 2018-11-01
2
10
 
3
11
  - Process messages to the same message group ID one by one
data/lib/shoryuken.rb CHANGED
@@ -77,7 +77,9 @@ module Shoryuken
77
77
  :default_worker_options=,
78
78
  :on_start,
79
79
  :on_stop,
80
- :on
80
+ :on,
81
+ :cache_visiblity_timeout?,
82
+ :cache_visiblity_timeout=
81
83
  )
82
84
  end
83
85
 
@@ -23,6 +23,7 @@ module Shoryuken
23
23
  @@stop_callback = nil
24
24
  @@worker_executor = Worker::DefaultExecutor
25
25
  @@launcher_executor = nil
26
+ @@cache_visiblity_timeout = false
26
27
 
27
28
  class << self
28
29
  def active_job?
@@ -220,6 +221,14 @@ module Shoryuken
220
221
  def server?
221
222
  defined?(Shoryuken::CLI)
222
223
  end
224
+
225
+ def cache_visiblity_timeout?
226
+ @@cache_visiblity_timeout
227
+ end
228
+
229
+ def cache_visiblity_timeout=(cache_visiblity_timeout)
230
+ @@cache_visiblity_timeout = cache_visiblity_timeout
231
+ end
223
232
  end
224
233
  end
225
234
  end
@@ -14,7 +14,10 @@ module Shoryuken
14
14
  end
15
15
 
16
16
  def visibility_timeout
17
- queue_attributes.attributes[VISIBILITY_TIMEOUT_ATTR].to_i
17
+ # Always lookup for the latest visiblity when cache is disabled
18
+ # setting it to nil, forces re-lookup
19
+ @_visibility_timeout = nil unless Shoryuken.cache_visiblity_timeout?
20
+ @_visibility_timeout ||= queue_attributes.attributes[VISIBILITY_TIMEOUT_ATTR].to_i
18
21
  end
19
22
 
20
23
  def delete_messages(options)
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '4.0.1'.freeze
3
3
  end
@@ -2,8 +2,9 @@ module Shoryuken
2
2
  module Worker
3
3
  class InlineExecutor
4
4
  class << self
5
- def perform_async(worker_class, body, _options = {})
5
+ def perform_async(worker_class, body, options = {})
6
6
  body = JSON.dump(body) if body.is_a?(Hash)
7
+ queue_name = options.delete(:queue) || worker_class.get_shoryuken_options['queue']
7
8
 
8
9
  sqs_msg = OpenStruct.new(
9
10
  body: body,
@@ -13,7 +14,8 @@ module Shoryuken
13
14
  message_attributes: nil,
14
15
  message_id: nil,
15
16
  receipt_handle: nil,
16
- delete: nil
17
+ delete: nil,
18
+ queue_name: queue_name
17
19
  )
18
20
 
19
21
  call(worker_class, sqs_msg)
@@ -234,4 +234,41 @@ RSpec.describe Shoryuken::Queue do
234
234
  end
235
235
  end
236
236
  end
237
+
238
+ describe '#visiblity_timeout' do
239
+ let(:attribute_response) { double 'Aws::SQS::Types::GetQueueAttributesResponse' }
240
+
241
+ before do
242
+ allow(attribute_response).to(
243
+ receive(:attributes).and_return('VisibilityTimeout' => 30)
244
+ )
245
+ allow(subject).to receive(:url).and_return(queue_url)
246
+ end
247
+
248
+ context 'when cache is disabled' do
249
+ specify do
250
+ Shoryuken.cache_visiblity_timeout = false
251
+
252
+ expect(sqs).to(
253
+ receive(:get_queue_attributes).with(queue_url: queue_url, attribute_names: ['All']).and_return(attribute_response).exactly(3).times
254
+ )
255
+ expect(subject.visibility_timeout).to eq(30)
256
+ expect(subject.visibility_timeout).to eq(30)
257
+ expect(subject.visibility_timeout).to eq(30)
258
+ end
259
+ end
260
+
261
+ context 'when cache is enabled' do
262
+ it 'memoizes response' do
263
+ Shoryuken.cache_visiblity_timeout = true
264
+
265
+ expect(sqs).to(
266
+ receive(:get_queue_attributes).with(queue_url: queue_url, attribute_names: ['All']).and_return(attribute_response).once
267
+ )
268
+ expect(subject.visibility_timeout).to eq(30)
269
+ expect(subject.visibility_timeout).to eq(30)
270
+ expect(subject.visibility_timeout).to eq(30)
271
+ end
272
+ end
273
+ end
237
274
  end
data/spec/spec_helper.rb CHANGED
@@ -61,6 +61,8 @@ RSpec.configure do |config|
61
61
 
62
62
  Shoryuken.sqs_client_receive_message_opts.clear
63
63
 
64
+ Shoryuken.cache_visiblity_timeout = false
65
+
64
66
  allow(Concurrent).to receive(:global_io_executor).and_return(Concurrent::ImmediateExecutor.new)
65
67
  allow(Shoryuken).to receive(:active_job?).and_return(false)
66
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoryuken
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler