shoryuken 3.2.0 → 3.2.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 +4 -4
- data/.travis.yml +4 -3
- data/CHANGELOG.md +11 -0
- data/README.md +8 -0
- data/bin/cli/sqs.rb +9 -6
- data/lib/shoryuken.rb +2 -0
- data/lib/shoryuken/client.rb +6 -2
- data/lib/shoryuken/extensions/active_job_adapter.rb +20 -10
- data/lib/shoryuken/launcher.rb +1 -1
- data/lib/shoryuken/options.rb +9 -0
- data/lib/shoryuken/version.rb +1 -1
- data/spec/shoryuken/extensions/active_job_adapter_spec.rb +64 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 853cbc2248381c89a862aa63acfdeb632703d816
|
4
|
+
data.tar.gz: b1001217f9763abf0e64049842331c6b856e08af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92b37bae40181a8a5225618282904de81591e8c7a02503cad00f3c1c3c24dc33b428482ae03d6ba59aacf1e1f14142205313f85f9378becd7965a3f4caaeb698
|
7
|
+
data.tar.gz: 8d1fb407c004db0b992b2437043395673802fb5bb6d8065d691025469c05ea43bf517f96f7ae46bbd5fbdb1fc9ec74abe2788e38dccfdcacf55b88ff632b887d
|
data/.travis.yml
CHANGED
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
data/lib/shoryuken/client.rb
CHANGED
@@ -8,11 +8,15 @@ module Shoryuken
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def sqs
|
11
|
-
|
11
|
+
Shoryuken.sqs_client
|
12
12
|
end
|
13
13
|
|
14
14
|
def sqs=(sqs)
|
15
|
-
@@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
|
-
|
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
|
-
|
47
|
-
queue.send_message(message(job, delay_seconds: delay))
|
50
|
+
delay
|
48
51
|
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
def message(job, options = {})
|
53
|
+
def message(queue, job, options = {})
|
53
54
|
body = job.serialize
|
54
55
|
|
55
|
-
|
56
|
-
|
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)
|
data/lib/shoryuken/launcher.rb
CHANGED
data/lib/shoryuken/options.rb
CHANGED
@@ -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
|
|
data/lib/shoryuken/version.rb
CHANGED
@@ -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.
|
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-
|
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
|