shoryuken 5.0.6 → 5.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/specs.yml +62 -0
  3. data/.reek.yml +5 -0
  4. data/Appraisals +28 -0
  5. data/CHANGELOG.md +48 -0
  6. data/Gemfile +3 -1
  7. data/README.md +21 -1
  8. data/Rakefile +15 -1
  9. data/bin/cli/sqs.rb +50 -5
  10. data/gemfiles/.gitignore +1 -0
  11. data/gemfiles/rails_4_2.gemfile +20 -0
  12. data/gemfiles/rails_5_2.gemfile +21 -0
  13. data/gemfiles/rails_6_0.gemfile +21 -0
  14. data/gemfiles/rails_6_1.gemfile +21 -0
  15. data/lib/shoryuken.rb +1 -0
  16. data/lib/shoryuken/environment_loader.rb +3 -0
  17. data/lib/shoryuken/extensions/active_job_adapter.rb +25 -18
  18. data/lib/shoryuken/extensions/active_job_extensions.rb +38 -0
  19. data/lib/shoryuken/manager.rb +10 -4
  20. data/lib/shoryuken/polling/base.rb +2 -0
  21. data/lib/shoryuken/polling/strict_priority.rb +6 -0
  22. data/lib/shoryuken/polling/weighted_round_robin.rb +11 -0
  23. data/lib/shoryuken/version.rb +1 -1
  24. data/shoryuken.gemspec +0 -1
  25. data/spec/integration/launcher_spec.rb +29 -2
  26. data/spec/shared_examples_for_active_job.rb +226 -9
  27. data/spec/shoryuken/environment_loader_spec.rb +22 -2
  28. data/spec/shoryuken/extensions/active_job_adapter_spec.rb +1 -1
  29. data/spec/shoryuken/extensions/active_job_base_spec.rb +84 -0
  30. data/spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb +4 -0
  31. data/spec/shoryuken/extensions/active_job_wrapper_spec.rb +20 -0
  32. data/spec/shoryuken/manager_spec.rb +24 -0
  33. data/spec/shoryuken/polling/strict_priority_spec.rb +10 -0
  34. data/spec/shoryuken/polling/weighted_round_robin_spec.rb +10 -0
  35. data/spec/spec_helper.rb +5 -9
  36. metadata +16 -19
  37. data/.travis.yml +0 -30
@@ -57,11 +57,11 @@ RSpec.describe Shoryuken::EnvironmentLoader do
57
57
  ActiveJob::Base.queue_name_delimiter = '_'
58
58
 
59
59
  allow(Shoryuken).to receive(:active_job?).and_return(true)
60
- end
61
60
 
62
- specify do
63
61
  Shoryuken.active_job_queue_name_prefixing = true
62
+ end
64
63
 
64
+ specify do
65
65
  Shoryuken.options[:queues] = ['queue1', ['queue2', 2]]
66
66
 
67
67
  Shoryuken.options[:groups] = {
@@ -73,6 +73,26 @@ RSpec.describe Shoryuken::EnvironmentLoader do
73
73
  expect(Shoryuken.groups['default'][:queues]).to eq(%w[test_queue1 test_queue2 test_queue2])
74
74
  expect(Shoryuken.groups['group1'][:queues]).to eq(%w[test_group1_queue1 test_group1_queue2])
75
75
  end
76
+
77
+ it 'does not prefix url-based queues' do
78
+ Shoryuken.options[:queues] = ['https://example.com/test_queue1']
79
+ Shoryuken.options[:groups] = {'group1' => {queues: ['https://example.com/test_group1_queue1']}}
80
+
81
+ subject.load
82
+
83
+ expect(Shoryuken.groups['default'][:queues]).to(eq(['https://example.com/test_queue1']))
84
+ expect(Shoryuken.groups['group1'][:queues]).to(eq(['https://example.com/test_group1_queue1']))
85
+ end
86
+
87
+ it 'does not prefix arn-based queues' do
88
+ Shoryuken.options[:queues] = ['arn:aws:sqs:fake-region-1:1234:test_queue1']
89
+ Shoryuken.options[:groups] = {'group1' => {queues: ['arn:aws:sqs:fake-region-1:1234:test_group1_queue1']}}
90
+
91
+ subject.load
92
+
93
+ expect(Shoryuken.groups['default'][:queues]).to(eq(['arn:aws:sqs:fake-region-1:1234:test_queue1']))
94
+ expect(Shoryuken.groups['group1'][:queues]).to(eq(['arn:aws:sqs:fake-region-1:1234:test_group1_queue1']))
95
+ end
76
96
  end
77
97
  describe "#setup_options" do
78
98
  let (:cli_queues) { { "queue1"=> 10, "queue2" => 20 } }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'shoryuken/extensions/active_job_adapter'
3
2
  require 'shared_examples_for_active_job'
3
+ require 'shoryuken/extensions/active_job_adapter'
4
4
 
5
5
  RSpec.describe ActiveJob::QueueAdapters::ShoryukenAdapter do
6
6
  include_examples 'active_job_adapters'
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'active_job'
3
+ require 'shoryuken/extensions/active_job_extensions'
4
+ require 'shoryuken/extensions/active_job_adapter'
5
+
6
+ RSpec.describe ActiveJob::Base do
7
+ let(:queue_adapter) { ActiveJob::QueueAdapters::ShoryukenAdapter.new }
8
+
9
+ subject do
10
+ worker_class = Class.new(described_class)
11
+ Object.const_set :MyWorker, worker_class
12
+ worker_class.queue_adapter = queue_adapter
13
+ worker_class
14
+ end
15
+
16
+ after do
17
+ Object.send :remove_const, :MyWorker
18
+ end
19
+
20
+ describe '#perform_now' do
21
+ it 'allows keyward args' do
22
+ collaborator = double 'worker collaborator'
23
+ subject.send(:define_method, :perform) do |**kwargs|
24
+ collaborator.foo(**kwargs)
25
+ end
26
+ expect(collaborator).to receive(:foo).with(foo: 'bar')
27
+ subject.perform_now foo: 'bar'
28
+ end
29
+ end
30
+
31
+ describe '#perform_later' do
32
+ it 'calls enqueue on the adapter with the expected job' do
33
+ expect(queue_adapter).to receive(:enqueue) do |job|
34
+ expect(job.arguments).to eq([1, 2])
35
+ end
36
+
37
+ subject.perform_later 1, 2
38
+ end
39
+
40
+ it 'passes message_group_id to the queue_adapter' do
41
+ expect(queue_adapter).to receive(:enqueue) do |job|
42
+ expect(job.sqs_send_message_parameters[:message_group_id]).to eq('group-2')
43
+ end
44
+
45
+ subject.set(message_group_id: 'group-2').perform_later 1, 2
46
+ end
47
+
48
+ it 'passes message_deduplication_id to the queue_adapter' do
49
+ expect(queue_adapter).to receive(:enqueue) do |job|
50
+ expect(job.sqs_send_message_parameters[:message_deduplication_id]).to eq('dedupe-id')
51
+ end
52
+
53
+ subject.set(message_deduplication_id: 'dedupe-id').perform_later 1, 2
54
+ end
55
+
56
+ it 'passes message_attributes to the queue_adapter' do
57
+ message_attributes = {
58
+ 'custom_tracing_id' => {
59
+ string_value: 'value',
60
+ data_type: 'String'
61
+ }
62
+ }
63
+ expect(queue_adapter).to receive(:enqueue) do |job|
64
+ expect(job.sqs_send_message_parameters[:message_attributes]).to eq(message_attributes)
65
+ end
66
+
67
+ subject.set(message_attributes: message_attributes).perform_later 1, 2
68
+ end
69
+
70
+ it 'passes message_system_attributes to the queue_adapter' do
71
+ message_system_attributes = {
72
+ 'AWSTraceHeader' => {
73
+ string_value: 'trace_id',
74
+ data_type: 'String'
75
+ }
76
+ }
77
+ expect(queue_adapter).to receive(:enqueue) do |job|
78
+ expect(job.sqs_send_message_parameters[:message_system_attributes]).to eq(message_system_attributes)
79
+ end
80
+
81
+ subject.set(message_system_attributes: message_system_attributes).perform_later 1, 2
82
+ end
83
+ end
84
+ end
@@ -10,6 +10,10 @@ RSpec.describe ActiveJob::QueueAdapters::ShoryukenConcurrentSendAdapter do
10
10
  let(:error_handler) { -> {} }
11
11
  let(:success_handler) { -> {} }
12
12
 
13
+ before do
14
+ allow(Concurrent).to receive(:global_io_executor).and_return(Concurrent::ImmediateExecutor.new)
15
+ end
16
+
13
17
  subject { described_class.new(success_handler, error_handler) }
14
18
 
15
19
  context 'when success' do
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'active_job'
3
+ require 'shoryuken/extensions/active_job_extensions'
4
+ require 'shoryuken/extensions/active_job_adapter'
5
+
6
+ RSpec.describe ActiveJob::QueueAdapters::ShoryukenAdapter::JobWrapper do
7
+ subject { described_class.new }
8
+
9
+ describe '#perform' do
10
+ it 'sets executions to reflect approximate receive count' do
11
+ attributes = { 'ApproximateReceiveCount' => '42' }
12
+ sqs_msg = double Shoryuken::Message, attributes: attributes
13
+ job_hash = { 'arguments' => [1, 2, 3] }
14
+ job_hash_with_executions = { 'arguments' => [1, 2, 3], 'executions' => 41 }
15
+ expect(ActiveJob::Base).to receive(:execute).with(job_hash_with_executions)
16
+
17
+ subject.perform sqs_msg, job_hash
18
+ end
19
+ end
20
+ end
@@ -139,4 +139,28 @@ RSpec.describe Shoryuken::Manager do
139
139
  subject.send(:dispatch_single_messages, q)
140
140
  end
141
141
  end
142
+
143
+ describe '#processor_done' do
144
+ let(:sqs_queue) { double Shoryuken::Queue }
145
+
146
+ before do
147
+ allow(Shoryuken::Client).to receive(:queues).with(queue).and_return(sqs_queue)
148
+ end
149
+
150
+ context 'when queue.fifo? is true' do
151
+ it 'calls message_processed on strategy' do
152
+ expect(sqs_queue).to receive(:fifo?).and_return(true)
153
+ expect(polling_strategy).to receive(:message_processed).with(queue)
154
+ subject.send(:processor_done, queue)
155
+ end
156
+ end
157
+
158
+ context 'when queue.fifo? is false' do
159
+ it 'does not call message_processed on strategy' do
160
+ expect(sqs_queue).to receive(:fifo?).and_return(false)
161
+ expect(polling_strategy).to_not receive(:message_processed)
162
+ subject.send(:processor_done, queue)
163
+ end
164
+ end
165
+ end
142
166
  end
@@ -145,4 +145,14 @@ RSpec.describe Shoryuken::Polling::StrictPriority do
145
145
  expect(subject.next_queue).to eq(queue3)
146
146
  end
147
147
  end
148
+
149
+ describe '#message_processed' do
150
+ it 'removes paused queue, adds to active queues' do
151
+ strategy = Shoryuken::Polling::StrictPriority.new([queue1, queue2])
152
+ strategy.send(:pause, queue1)
153
+ expect(strategy.active_queues).to eq([[queue2, 1]])
154
+ strategy.message_processed(queue1)
155
+ expect(strategy.active_queues).to eq([[queue1, 2], [queue2, 1]])
156
+ end
157
+ end
148
158
  end
@@ -104,4 +104,14 @@ RSpec.describe Shoryuken::Polling::WeightedRoundRobin do
104
104
  expect(subject.delay).to eq(1.0)
105
105
  end
106
106
  end
107
+
108
+ describe '#message_processed' do
109
+ it 'removes paused queue, adds to active queues' do
110
+ strategy = Shoryuken::Polling::WeightedRoundRobin.new([queue1, queue2])
111
+ strategy.send(:pause, queue1)
112
+ expect(strategy.active_queues).to eq([[queue2, 1]])
113
+ strategy.message_processed(queue1)
114
+ expect(strategy.active_queues).to eq([[queue2, 1], [queue1, 1]])
115
+ end
116
+ end
107
117
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
- require 'pry-byebug'
4
+ begin
5
+ require 'pry-byebug'
6
+ rescue LoadError
7
+ end
8
+
5
9
  require 'shoryuken'
6
10
  require 'json'
7
11
  require 'dotenv'
@@ -28,13 +32,6 @@ class TestWorker
28
32
  end
29
33
 
30
34
  RSpec.configure do |config|
31
- # Only run slow tests if SPEC_ALL=true and AWS_ACCESS_KEY_ID is present
32
- # The AWS_ACCESS_KEY_ID checker is because Travis CI
33
- # does not expose ENV variables to pull requests from forked repositories
34
- # http://docs.travis-ci.com/user/pull-requests/
35
- # config.filter_run_excluding slow: true if ENV['SPEC_ALL'] != 'true' || ENV['AWS_ACCESS_KEY_ID'].nil?
36
- config.filter_run_excluding slow: true
37
-
38
35
  config.before do
39
36
  Shoryuken::Client.class_variable_set :@@queues, {}
40
37
 
@@ -63,7 +60,6 @@ RSpec.configure do |config|
63
60
 
64
61
  Shoryuken.cache_visibility_timeout = false
65
62
 
66
- allow(Concurrent).to receive(:global_io_executor).and_return(Concurrent::ImmediateExecutor.new)
67
63
  allow(Shoryuken).to receive(:active_job?).and_return(false)
68
64
  end
69
65
  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: 5.0.6
4
+ version: 5.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: pry-byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 3.9.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 3.9.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -118,10 +104,12 @@ extra_rdoc_files: []
118
104
  files:
119
105
  - ".codeclimate.yml"
120
106
  - ".github/FUNDING.yml"
107
+ - ".github/workflows/specs.yml"
121
108
  - ".gitignore"
109
+ - ".reek.yml"
122
110
  - ".rspec"
123
111
  - ".rubocop.yml"
124
- - ".travis.yml"
112
+ - Appraisals
125
113
  - CHANGELOG.md
126
114
  - Gemfile
127
115
  - Gemfile.aws-sdk-core-v2
@@ -133,6 +121,11 @@ files:
133
121
  - bin/shoryuken
134
122
  - examples/bootstrap_queues.rb
135
123
  - examples/default_worker.rb
124
+ - gemfiles/.gitignore
125
+ - gemfiles/rails_4_2.gemfile
126
+ - gemfiles/rails_5_2.gemfile
127
+ - gemfiles/rails_6_0.gemfile
128
+ - gemfiles/rails_6_1.gemfile
136
129
  - lib/shoryuken.rb
137
130
  - lib/shoryuken/body_parser.rb
138
131
  - lib/shoryuken/client.rb
@@ -141,6 +134,7 @@ files:
141
134
  - lib/shoryuken/environment_loader.rb
142
135
  - lib/shoryuken/extensions/active_job_adapter.rb
143
136
  - lib/shoryuken/extensions/active_job_concurrent_send_adapter.rb
137
+ - lib/shoryuken/extensions/active_job_extensions.rb
144
138
  - lib/shoryuken/fetcher.rb
145
139
  - lib/shoryuken/launcher.rb
146
140
  - lib/shoryuken/logging.rb
@@ -176,7 +170,9 @@ files:
176
170
  - spec/shoryuken/default_worker_registry_spec.rb
177
171
  - spec/shoryuken/environment_loader_spec.rb
178
172
  - spec/shoryuken/extensions/active_job_adapter_spec.rb
173
+ - spec/shoryuken/extensions/active_job_base_spec.rb
179
174
  - spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb
175
+ - spec/shoryuken/extensions/active_job_wrapper_spec.rb
180
176
  - spec/shoryuken/fetcher_spec.rb
181
177
  - spec/shoryuken/manager_spec.rb
182
178
  - spec/shoryuken/middleware/chain_spec.rb
@@ -217,8 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
213
  - !ruby/object:Gem::Version
218
214
  version: '0'
219
215
  requirements: []
220
- rubyforge_project:
221
- rubygems_version: 2.7.6
216
+ rubygems_version: 3.0.1
222
217
  signing_key:
223
218
  specification_version: 4
224
219
  summary: Shoryuken is a super efficient AWS SQS thread based message processor
@@ -232,7 +227,9 @@ test_files:
232
227
  - spec/shoryuken/default_worker_registry_spec.rb
233
228
  - spec/shoryuken/environment_loader_spec.rb
234
229
  - spec/shoryuken/extensions/active_job_adapter_spec.rb
230
+ - spec/shoryuken/extensions/active_job_base_spec.rb
235
231
  - spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb
232
+ - spec/shoryuken/extensions/active_job_wrapper_spec.rb
236
233
  - spec/shoryuken/fetcher_spec.rb
237
234
  - spec/shoryuken/manager_spec.rb
238
235
  - spec/shoryuken/middleware/chain_spec.rb
data/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.4.4
5
- - 2.5.1
6
- - 2.6.3
7
-
8
- notifications:
9
- email:
10
- on_success: change
11
- on_failure: always
12
-
13
- gemfile:
14
- - Gemfile
15
- - Gemfile.aws-sdk-core-v2
16
-
17
- env:
18
- - SPEC_ALL=true
19
-
20
- script: bundle exec rspec spec
21
-
22
- before_install:
23
- - gem install bundler -v '< 2'
24
-
25
- after_success:
26
- - bundle exec codeclimate-test-reporter
27
-
28
- addons:
29
- code_climate:
30
- repo_token: 7709fd21981bb9d2658647a66d959415a1029a83f1c199573828797944f26c52