shoryuken 5.3.1 → 5.3.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: c730786f3c97f263b00320693e0ea95af12495bb83805a39461de93b526b4d2a
4
- data.tar.gz: a7a7fbb4bd5a1c006c1573261c607c6c77968575af901a8671dea4da6e4282c5
3
+ metadata.gz: 1002845b2232c5f7491b2839d7851be5afdb79a3a11e73e2249b81e1f2ea4ec4
4
+ data.tar.gz: 8398fa557fba47360763bb83ea4e0f529b2c69bad8b15fb3163e03c517b460d8
5
5
  SHA512:
6
- metadata.gz: 3bc9237605e5f9667f0e22bdae6ca1553b2f2a08357f2f7da465fa4f812d3abcafd6ef21c05ef553dac13dcb405fa658d13bada5be235743974978fc7829b6d2
7
- data.tar.gz: 54737eb8fc32b4a486d62f1ef626336e0493ae70475efb1a99e163ebd960d2e38c99506ccf8cafcd3502bd52a2279619601150634e7dbf3134b38913bb0283e8
6
+ metadata.gz: 010d2f45fe45e6967435b57c1f0c7601f9d3a43a8c1108edbf97b303e60e108e0c6be1ba28915a43bc84f5904bd7f3d634916251b8b1c0d83143d75bdccaaca7
7
+ data.tar.gz: 00c8f19de3a9fd241bb236023479bd5c3bd27f731001f036377c05b75c18bce119b08666eb13649606904e2950f937f52615eba84facb44074099fde1fc97534
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [v5.3.2] - 2022-01-19
2
+
3
+ - (Bugfix) Preserve queue weights when unpausing queues
4
+ - [#687](https://github.com/ruby-shoryuken/shoryuken/pull/687)
5
+
6
+ - Improve error message on startup when shoryuken has insufficient permissions to access a queue
7
+ - [#691](https://github.com/ruby-shoryuken/shoryuken/pull/691)
8
+
1
9
  ## [v5.3.1] - 2022-01-07
2
10
 
3
11
  - (Bugfix) Fix issue where, when using the TSTP or USR1 signals for soft shutdowns, it was possible for shoryuken to terminate without first attempting to handle all messages it fetched from SQS
@@ -159,9 +159,17 @@ module Shoryuken
159
159
 
160
160
  return if non_existent_queues.none?
161
161
 
162
+ # NOTE: HEREDOC's ~ operator removes indents, but is only available Ruby 2.3+
163
+ # See github PR: https://github.com/ruby-shoryuken/shoryuken/pull/691#issuecomment-1007653595
164
+ error_msg = <<-MSG.gsub(/^\s+/, '')
165
+ The specified queue(s) #{non_existent_queues.join(', ')} do not exist.
166
+ Try 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings.
167
+ It's also possible that you don't have permission to access the specified queues.
168
+ MSG
169
+
162
170
  fail(
163
171
  ArgumentError,
164
- "The specified queue(s) #{non_existent_queues.join(', ')} do not exist.\nTry 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings"
172
+ error_msg
165
173
  )
166
174
  end
167
175
 
@@ -39,8 +39,10 @@ module Shoryuken
39
39
  end
40
40
 
41
41
  def message_processed(queue)
42
- logger.debug "Unpausing #{queue}"
43
- @paused_until[queue] = Time.now
42
+ if queue_paused?(queue)
43
+ logger.debug "Unpausing #{queue}"
44
+ @paused_until[queue] = Time.at 0
45
+ end
44
46
  end
45
47
 
46
48
  private
@@ -36,12 +36,10 @@ module Shoryuken
36
36
  end
37
37
 
38
38
  def message_processed(queue)
39
- return if @paused_queues.empty?
39
+ paused_queue = @paused_queues.find { |_time, name| name == queue }
40
+ return unless paused_queue
40
41
 
41
- logger.debug "Unpausing #{queue}"
42
- @paused_queues.reject! { |_time, name| name == queue }
43
- @queues << queue
44
- @queues.uniq!
42
+ paused_queue[0] = Time.at 0
45
43
  end
46
44
 
47
45
  private
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '5.3.1'.freeze
2
+ VERSION = '5.3.2'.freeze
3
3
  end
@@ -4,6 +4,36 @@ require 'active_job'
4
4
  RSpec.describe Shoryuken::EnvironmentLoader do
5
5
  subject { described_class.new({}) }
6
6
 
7
+ describe '#load' do
8
+ before do
9
+ Shoryuken.groups.clear
10
+ # See issue: https://stackoverflow.com/a/63699568 for stubbing AWS errors
11
+ allow(Shoryuken::Client)
12
+ .to receive(:queues)
13
+ .with('stubbed_queue')
14
+ .and_raise(Aws::SQS::Errors::NonExistentQueue.new(nil, nil))
15
+ allow(subject).to receive(:load_rails)
16
+ allow(subject).to receive(:prefix_active_job_queue_names)
17
+ allow(subject).to receive(:require_workers)
18
+ allow(subject).to receive(:validate_workers)
19
+ allow(subject).to receive(:patch_deprecated_workers)
20
+ Shoryuken.options[:groups] = [['custom', { queues: ['stubbed_queue'] }]]
21
+ end
22
+
23
+ context "when given queues don't exist" do
24
+ specify do
25
+ expect { subject.load }.to raise_error(
26
+ ArgumentError,
27
+ <<-MSG.gsub(/^\s+/, '')
28
+ The specified queue(s) stubbed_queue do not exist.
29
+ Try 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings.
30
+ It's also possible that you don't have permission to access the specified queues.
31
+ MSG
32
+ )
33
+ end
34
+ end
35
+ end
36
+
7
37
  describe '#parse_queues loads default queues' do
8
38
  before do
9
39
  allow(subject).to receive(:load_rails)
@@ -34,7 +64,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
34
64
 
35
65
  specify do
36
66
  Shoryuken.options[:queues] = ['queue1', 'queue2'] # default queues
37
- Shoryuken.options[:groups] = [[ 'custom', { queues: ['queue3'], delay: 25 }]]
67
+ Shoryuken.options[:groups] = [['custom', { queues: ['queue3'], delay: 25 }]]
38
68
  subject.load
39
69
 
40
70
  expect(Shoryuken.groups['default'][:queues]).to eq(%w[queue1 queue2])
@@ -44,7 +74,6 @@ RSpec.describe Shoryuken::EnvironmentLoader do
44
74
  end
45
75
  end
46
76
 
47
-
48
77
  describe '#prefix_active_job_queue_names' do
49
78
  before do
50
79
  allow(subject).to receive(:load_rails)
@@ -76,7 +105,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
76
105
 
77
106
  it 'does not prefix url-based queues' do
78
107
  Shoryuken.options[:queues] = ['https://example.com/test_queue1']
79
- Shoryuken.options[:groups] = {'group1' => {queues: ['https://example.com/test_group1_queue1']}}
108
+ Shoryuken.options[:groups] = { 'group1' => { queues: ['https://example.com/test_group1_queue1'] } }
80
109
 
81
110
  subject.load
82
111
 
@@ -86,7 +115,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
86
115
 
87
116
  it 'does not prefix arn-based queues' do
88
117
  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']}}
118
+ Shoryuken.options[:groups] = { 'group1' => { queues: ['arn:aws:sqs:fake-region-1:1234:test_group1_queue1'] } }
90
119
 
91
120
  subject.load
92
121
 
@@ -94,9 +123,11 @@ RSpec.describe Shoryuken::EnvironmentLoader do
94
123
  expect(Shoryuken.groups['group1'][:queues]).to(eq(['arn:aws:sqs:fake-region-1:1234:test_group1_queue1']))
95
124
  end
96
125
  end
126
+
97
127
  describe "#setup_options" do
98
- let (:cli_queues) { { "queue1"=> 10, "queue2" => 20 } }
99
- let (:config_queues) { [["queue1", 8], ["queue2", 4]] }
128
+ let(:cli_queues) { { "queue1" => 10, "queue2" => 20 } }
129
+ let(:config_queues) { [["queue1", 8], ["queue2", 4]] }
130
+
100
131
  context "when given queues through config and CLI" do
101
132
  specify do
102
133
  allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues })
@@ -104,6 +135,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
104
135
  expect(Shoryuken.options[:queues]).to eq(cli_queues)
105
136
  end
106
137
  end
138
+
107
139
  context "when given queues through config only" do
108
140
  specify do
109
141
  allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues })
@@ -111,6 +143,7 @@ RSpec.describe Shoryuken::EnvironmentLoader do
111
143
  expect(Shoryuken.options[:queues]).to eq(config_queues)
112
144
  end
113
145
  end
146
+
114
147
  context "when given queues through CLI only" do
115
148
  specify do
116
149
  Shoryuken::EnvironmentLoader.setup_options(queues: cli_queues)
@@ -106,12 +106,37 @@ RSpec.describe Shoryuken::Polling::WeightedRoundRobin do
106
106
  end
107
107
 
108
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]])
109
+ it 'removes delay from paused queue' do
110
+ queues << queue1
111
+ queues << queue2
112
+
113
+ expect(subject.next_queue).to eq(queue1)
114
+ subject.messages_found(queue1, 0) # pauses queue1
115
+
116
+ expect(subject.active_queues).to eq([[queue2, 1]])
117
+
118
+ subject.message_processed(queue1) # marks queue1 to be unpaused
119
+
120
+ expect(subject.next_queue).to eq(queue2) # implicitly unpauses queue1
121
+ expect(subject.active_queues).to eq([[queue1, 1], [queue2, 1]])
122
+ end
123
+
124
+ it 'preserves weight of queues when unpausing' do
125
+ queues << queue1
126
+ queues << queue1
127
+ queues << queue2
128
+
129
+ expect(subject.next_queue).to eq(queue1)
130
+ subject.messages_found(queue1, 1)
131
+
132
+ expect(subject.next_queue).to eq(queue2)
133
+ subject.messages_found(queue2, 0) # pauses queue2
134
+
135
+ expect(subject.active_queues).to eq([[queue1, 2]])
136
+ subject.message_processed(queue2) # marks queue2 to be unpaused
137
+
138
+ expect(subject.next_queue).to eq(queue1) # implicitly unpauses queue2
139
+ expect(subject.active_queues).to eq([[queue1, 2], [queue2, 1]])
115
140
  end
116
141
  end
117
142
  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.3.1
4
+ version: 5.3.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: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv