shoryuken 3.2.0 → 3.2.1

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
  SHA1:
3
- metadata.gz: f74e5fbb599fe5bbe41bed5fd542c0c1fdcc2d35
4
- data.tar.gz: 6099d42682b5e2a1797d7cdbdc7bf27b344b692c
3
+ metadata.gz: 853cbc2248381c89a862aa63acfdeb632703d816
4
+ data.tar.gz: b1001217f9763abf0e64049842331c6b856e08af
5
5
  SHA512:
6
- metadata.gz: f076e8f427f39ca92be4f27be819350d90270ce9e695d1173a6944b82d16680d11afd78a0075dd549e0a2c6031e6d5708c306cb245c4d7dfcc69d8a5e7151bc7
7
- data.tar.gz: 2fd34c84e6260df3c35427ffb27d3d067fc1ea11469609d61e8eedd465e4516d75e052079b5195ede7c7917ad3c97bb39c5440bc5436ae3ab2581f3fb72bad31
6
+ metadata.gz: 92b37bae40181a8a5225618282904de81591e8c7a02503cad00f3c1c3c24dc33b428482ae03d6ba59aacf1e1f14142205313f85f9378becd7965a3f4caaeb698
7
+ data.tar.gz: 8d1fb407c004db0b992b2437043395673802fb5bb6d8065d691025469c05ea43bf517f96f7ae46bbd5fbdb1fc9ec74abe2788e38dccfdcacf55b88ff632b887d
data/.travis.yml CHANGED
@@ -3,9 +3,10 @@ language: ruby
3
3
  rvm:
4
4
  - 2.0.0
5
5
  - 2.1.10
6
- - 2.2.0
7
- - 2.3.3
8
- - 2.4.1
6
+ - 2.2.9
7
+ - 2.3.6
8
+ - 2.4.3
9
+ - 2.5.0
9
10
 
10
11
  notifications:
11
12
  email:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [v3.2.1] - 2018-02-12
2
+
3
+ - Support FIFO queues in `shoryuken sqs` commands
4
+ - [#473](https://github.com/phstc/shoryuken/pull/473)
5
+
6
+ - Allow customizing the default executor launcher
7
+ - [#469](https://github.com/phstc/shoryuken/pull/469)
8
+
9
+ - Exclude job_id from message deduplication when ActiveJob
10
+ - [#462](https://github.com/phstc/shoryuken/pull/462)
11
+
1
12
  ## [v3.2.0] - 2018-01-03
2
13
 
3
14
  - Preserve parent worker class options
data/README.md CHANGED
@@ -31,6 +31,14 @@ Add this line to your application's Gemfile:
31
31
  gem 'shoryuken'
32
32
  ```
33
33
 
34
+ If you are using AWS SDK version 3, please also add this line:
35
+
36
+ ```ruby
37
+ gem 'aws-sdk-sqs'
38
+ ```
39
+
40
+ The extra gem `aws-sdk-sqs` is required in order to keep Shoryuken compatible with AWS SDK version 2 and 3.
41
+
34
42
  And then execute:
35
43
 
36
44
  ```shell
data/bin/cli/sqs.rb CHANGED
@@ -8,12 +8,14 @@ module Shoryuken
8
8
 
9
9
  no_commands do
10
10
  def normalize_dump_message(message)
11
- message[:id] = message.delete(:message_id)
12
- message[:message_body] = message.delete(:body)
13
- message.delete(:receipt_handle)
14
- message.delete(:md5_of_body)
15
- message.delete(:md5_of_message_attributes)
16
- message
11
+ attributes = message[:attributes]
12
+ {
13
+ id: message[:message_id],
14
+ message_body: message[:body],
15
+ message_attributes: message[:message_attributes],
16
+ message_deduplication_id: attributes['MessageDeduplicationId'],
17
+ message_group_id: attributes['MessageGroupId']
18
+ }
17
19
  end
18
20
 
19
21
  def sqs
@@ -59,6 +61,7 @@ module Shoryuken
59
61
  messages = sqs.receive_message(
60
62
  queue_url: url,
61
63
  max_number_of_messages: batch_size,
64
+ attribute_names: ['All'],
62
65
  message_attribute_names: ['All']
63
66
  ).messages
64
67
 
data/lib/shoryuken.rb CHANGED
@@ -53,6 +53,8 @@ module Shoryuken
53
53
  :worker_registry=,
54
54
  :worker_executor,
55
55
  :worker_executor=,
56
+ :launcher_executor,
57
+ :launcher_executor=,
56
58
  :polling_strategy,
57
59
  :start_callback,
58
60
  :start_callback=,
@@ -8,11 +8,15 @@ module Shoryuken
8
8
  end
9
9
 
10
10
  def sqs
11
- @@sqs ||= Shoryuken.sqs_client
11
+ Shoryuken.sqs_client
12
12
  end
13
13
 
14
14
  def sqs=(sqs)
15
- @@sqs = sqs
15
+ # Since the @@queues values (Shoryuken::Queue objects) are built referencing @@sqs, if it changes, we need to
16
+ # re-build them on subsequent calls to `.queues(name)`.
17
+ @@queues = {}
18
+
19
+ Shoryuken.sqs_client = sqs
16
20
  end
17
21
  end
18
22
  end
@@ -30,30 +30,40 @@ module ActiveJob
30
30
  end
31
31
  end
32
32
 
33
- def enqueue(job) #:nodoc:
33
+ def enqueue(job, options = {}) #:nodoc:
34
34
  register_worker!(job)
35
35
 
36
36
  queue = Shoryuken::Client.queues(job.queue_name)
37
- queue.send_message(message(job))
37
+ queue.send_message(message(queue, job, options))
38
38
  end
39
39
 
40
40
  def enqueue_at(job, timestamp) #:nodoc:
41
- register_worker!(job)
41
+ enqueue(job, delay_seconds: calculate_delay(timestamp))
42
+ end
43
+
44
+ private
42
45
 
46
+ def calculate_delay(timestamp)
43
47
  delay = (timestamp - Time.current.to_f).round
44
48
  raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
45
49
 
46
- queue = Shoryuken::Client.queues(job.queue_name)
47
- queue.send_message(message(job, delay_seconds: delay))
50
+ delay
48
51
  end
49
52
 
50
- private
51
-
52
- def message(job, options = {})
53
+ def message(queue, job, options = {})
53
54
  body = job.serialize
54
55
 
55
- { message_body: body,
56
- message_attributes: message_attributes }.merge(options)
56
+ msg = {}
57
+
58
+ if queue.fifo?
59
+ # See https://github.com/phstc/shoryuken/issues/457
60
+ msg[:message_deduplication_id] = Digest::SHA256.hexdigest(JSON.dump(body.except('job_id')))
61
+ end
62
+
63
+ msg[:message_body] = body
64
+ msg[:message_attributes] = message_attributes
65
+
66
+ msg.merge(options)
57
67
  end
58
68
 
59
69
  def register_worker!(job)
@@ -35,7 +35,7 @@ module Shoryuken
35
35
  private
36
36
 
37
37
  def executor
38
- Concurrent.global_io_executor
38
+ @_executor ||= Shoryuken.launcher_executor || Concurrent.global_io_executor
39
39
  end
40
40
 
41
41
  def start_managers
@@ -22,6 +22,7 @@ module Shoryuken
22
22
  @@start_callback = nil
23
23
  @@stop_callback = nil
24
24
  @@worker_executor = Worker::DefaultExecutor
25
+ @@launcher_executor = nil
25
26
 
26
27
  class << self
27
28
  def active_job?
@@ -65,6 +66,14 @@ module Shoryuken
65
66
  @@worker_executor = worker_executor
66
67
  end
67
68
 
69
+ def launcher_executor
70
+ @@launcher_executor
71
+ end
72
+
73
+ def launcher_executor=(launcher_executor)
74
+ @@launcher_executor = launcher_executor
75
+ end
76
+
68
77
  def polling_strategy(group)
69
78
  strategy = (group == 'default' ? options : options[:groups].to_h[group]).to_h[:polling_strategy]
70
79
 
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '3.2.0'.freeze
2
+ VERSION = '3.2.1'.freeze
3
3
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'active_job'
3
+ require 'shoryuken/extensions/active_job_adapter'
4
+
5
+ RSpec.describe ActiveJob::QueueAdapters::ShoryukenAdapter do
6
+ let(:job) { double 'Job', id: '123', queue_name: 'queue' }
7
+ let(:fifo) { false }
8
+ let(:queue) { double 'Queue', fifo?: fifo }
9
+
10
+ before do
11
+ allow(Shoryuken::Client).to receive(:queues).with(job.queue_name).and_return(queue)
12
+ allow(job).to receive(:serialize).and_return({
13
+ 'job_class' => 'Worker',
14
+ 'job_id' => job.id,
15
+ 'queue_name' => job.queue_name,
16
+ 'arguments' => nil,
17
+ 'locale' => nil
18
+ })
19
+ end
20
+
21
+ describe '#enqueue' do
22
+ specify do
23
+ expect(queue).to receive(:send_message) do |hash|
24
+ expect(hash[:message_deduplication_id]).to_not be
25
+ end
26
+ expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
27
+
28
+ subject.enqueue(job)
29
+ end
30
+
31
+ context 'when fifo' do
32
+ let(:fifo) { true }
33
+
34
+ it 'does not include job_id in the deduplication_id' do
35
+ expect(queue).to receive(:send_message) do |hash|
36
+ message_deduplication_id = Digest::SHA256.hexdigest(JSON.dump(job.serialize.except('job_id')))
37
+
38
+ expect(hash[:message_deduplication_id]).to eq(message_deduplication_id)
39
+ end
40
+ expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
41
+
42
+ subject.enqueue(job)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#enqueue_at' do
48
+ specify do
49
+ delay = 1
50
+
51
+ expect(queue).to receive(:send_message) do |hash|
52
+ expect(hash[:message_deduplication_id]).to_not be
53
+ expect(hash[:delay_seconds]).to eq(delay)
54
+ end
55
+
56
+ expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
57
+
58
+ # need to figure out what to require Time.current and N.minutes to remove the stub
59
+ allow(subject).to receive(:calculate_delay).and_return(delay)
60
+
61
+ subject.enqueue_at(job, nil)
62
+ end
63
+ end
64
+ 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: 3.2.0
4
+ version: 3.2.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-01-03 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,6 +186,7 @@ files:
186
186
  - spec/shoryuken/core_ext_spec.rb
187
187
  - spec/shoryuken/default_worker_registry_spec.rb
188
188
  - spec/shoryuken/environment_loader_spec.rb
189
+ - spec/shoryuken/extensions/active_job_adapter_spec.rb
189
190
  - spec/shoryuken/fetcher_spec.rb
190
191
  - spec/shoryuken/manager_spec.rb
191
192
  - spec/shoryuken/middleware/chain_spec.rb
@@ -239,6 +240,7 @@ test_files:
239
240
  - spec/shoryuken/core_ext_spec.rb
240
241
  - spec/shoryuken/default_worker_registry_spec.rb
241
242
  - spec/shoryuken/environment_loader_spec.rb
243
+ - spec/shoryuken/extensions/active_job_adapter_spec.rb
242
244
  - spec/shoryuken/fetcher_spec.rb
243
245
  - spec/shoryuken/manager_spec.rb
244
246
  - spec/shoryuken/middleware/chain_spec.rb