shoryuken 5.2.3 → 5.3.0

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: 0f2f8c9e8573b699391a74a70d26756e106ccf72b3df9a6fccc32b72d13ec0cd
4
- data.tar.gz: 6a009d5a5e571da339d52a08f4ccda19f144ce06132f4a65e95fabc39aeffad4
3
+ metadata.gz: 9f4f8cbfdd04c4d39b7f672c549b0d112f64c99a8df4807b83083b57dab8addd
4
+ data.tar.gz: 0cfeaef14f59567382eefacb342be547a43f7dc7a118a3f824a6bdc88710ceea
5
5
  SHA512:
6
- metadata.gz: e359eee09d82a917c4e13541a121c61f78587421a7e5977052552a4f18512eeb9a2eb720ebc8adf323d0a33fd979b37e9c059a95b5b180eda93cab5a3e034f6b
7
- data.tar.gz: 5217287d2b7f66125852ac0b824353d934a2a8568e2dc07ca3c98f8991cad1a0dafbda87967a407bc5efaea62b1cafa85708e1ea17ccb659b2743878d079a267
6
+ metadata.gz: 0ee996f0a835c46c50adaef43f413374505df454e8e696c5a1faaefdd9c28a4ed7922f620b56f800a3aad152881c66dd812bad573fec91f9d2ed9bd168c468f8
7
+ data.tar.gz: 9208b28922188d06f60ade86d0c53d56c6bedbc8577e908d5aa4a819c23cc13889fdea5dcb8875608495f2bb785f3b198bddbdb4fd93f3d6f7fa53d2f9cfec3f
data/.gitignore CHANGED
@@ -25,4 +25,4 @@ shoryuken.yml
25
25
  *.log
26
26
  .env
27
27
  rubocop.html
28
- .byebug_history
28
+ .byebug_history
data/.rubocop.yml CHANGED
@@ -23,7 +23,7 @@ Metrics/AbcSize:
23
23
  # because codeclimate already give that for us with more details
24
24
  Enabled: false
25
25
 
26
- Metrics/LineLength:
26
+ Layout/LineLength:
27
27
  Max: 125
28
28
 
29
29
  Style/Alias:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [v5.3.0] - 2021-10-31
2
+
3
+ - (Refactor) Use Forwardable within Message to avoid method boilerplate
4
+ - [#681](https://github.com/ruby-shoryuken/shoryuken/pull/681)
5
+
6
+ - Add basic health check API
7
+ - [#679](https://github.com/ruby-shoryuken/shoryuken/pull/679)
8
+
1
9
  ## [v5.2.3] - 2021-07-29
2
10
 
3
11
  - Fire new `:utilization_update` event any time a worker pool's utilization changes
data/Gemfile CHANGED
@@ -16,5 +16,5 @@ end
16
16
  group :development do
17
17
  gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git'
18
18
  gem 'pry-byebug', '3.9.0'
19
- gem 'rubocop'
19
+ gem 'rubocop', '<= 1.12'
20
20
  end
@@ -32,6 +32,13 @@ module Shoryuken
32
32
  executor.wait_for_termination
33
33
  end
34
34
 
35
+ def healthy?
36
+ Shoryuken.groups.keys.all? do |group|
37
+ manager = @managers.find { |m| m.group == group }
38
+ manager && manager.running?
39
+ end
40
+ end
41
+
35
42
  private
36
43
 
37
44
  def executor
@@ -6,6 +6,8 @@ module Shoryuken
6
6
  # See https://github.com/phstc/shoryuken/issues/348#issuecomment-292847028
7
7
  MIN_DISPATCH_INTERVAL = 0.1
8
8
 
9
+ attr_reader :group
10
+
9
11
  def initialize(group, fetcher, polling_strategy, concurrency, executor)
10
12
  @group = group
11
13
  @fetcher = fetcher
@@ -21,12 +23,12 @@ module Shoryuken
21
23
  dispatch_loop
22
24
  end
23
25
 
24
- private
25
-
26
26
  def running?
27
27
  @running.true? && @executor.running?
28
28
  end
29
29
 
30
+ private
31
+
30
32
  def dispatch_loop
31
33
  return unless running?
32
34
 
@@ -1,5 +1,16 @@
1
1
  module Shoryuken
2
2
  class Message
3
+ extend Forwardable
4
+
5
+ def_delegators(:data,
6
+ :message_id,
7
+ :receipt_handle,
8
+ :md5_of_body,
9
+ :body,
10
+ :attributes,
11
+ :md5_of_message_attributes,
12
+ :message_attributes)
13
+
3
14
  attr_accessor :client, :queue_url, :queue_name, :data
4
15
 
5
16
  def initialize(client, queue, data)
@@ -29,33 +40,5 @@ module Shoryuken
29
40
  visibility_timeout: timeout
30
41
  )
31
42
  end
32
-
33
- def message_id
34
- data.message_id
35
- end
36
-
37
- def receipt_handle
38
- data.receipt_handle
39
- end
40
-
41
- def md5_of_body
42
- data.md5_of_body
43
- end
44
-
45
- def body
46
- data.body
47
- end
48
-
49
- def attributes
50
- data.attributes
51
- end
52
-
53
- def md5_of_message_attributes
54
- data.md5_of_message_attributes
55
- end
56
-
57
- def message_attributes
58
- data.message_attributes
59
- end
60
43
  end
61
44
  end
@@ -55,6 +55,10 @@ module Shoryuken
55
55
  end
56
56
  end
57
57
 
58
+ def healthy?
59
+ (@launcher && @launcher.healthy?) || false
60
+ end
61
+
58
62
  private
59
63
 
60
64
  def initialize_concurrent_logger
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '5.2.3'.freeze
2
+ VERSION = '5.3.0'.freeze
3
3
  end
data/lib/shoryuken.rb CHANGED
@@ -45,6 +45,10 @@ module Shoryuken
45
45
  @_shoryuken_options ||= Shoryuken::Options.new
46
46
  end
47
47
 
48
+ def self.healthy?
49
+ Shoryuken::Runner.instance.healthy?
50
+ end
51
+
48
52
  def_delegators(
49
53
  :shoryuken_options,
50
54
  :active_job?,
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'shoryuken/launcher'
3
+
4
+ RSpec.describe Shoryuken::Launcher do
5
+ let(:executor) do
6
+ # We can't use Concurrent.global_io_executor in these tests since once you
7
+ # shut down a thread pool, you can't start it back up. Instead, we create
8
+ # one new thread pool executor for each spec. We use a new
9
+ # CachedThreadPool, since that most closely resembles
10
+ # Concurrent.global_io_executor
11
+ Concurrent::CachedThreadPool.new auto_terminate: true
12
+ end
13
+
14
+ let(:first_group_manager) { double(:first_group_manager, group: 'first_group') }
15
+ let(:second_group_manager) { double(:second_group_manager, group: 'second_group') }
16
+ let(:first_queue) { "launcher_spec_#{SecureRandom.uuid}" }
17
+ let(:second_queue) { "launcher_spec_#{SecureRandom.uuid}" }
18
+
19
+ before do
20
+ Shoryuken.add_group('first_group', 1)
21
+ Shoryuken.add_group('second_group', 1)
22
+ Shoryuken.add_queue(first_queue, 1, 'first_group')
23
+ Shoryuken.add_queue(second_queue, 1, 'second_group')
24
+ allow(Shoryuken).to receive(:launcher_executor).and_return(executor)
25
+ allow(Shoryuken::Manager).to receive(:new).with('first_group', any_args).and_return(first_group_manager)
26
+ allow(Shoryuken::Manager).to receive(:new).with('second_group', any_args).and_return(second_group_manager)
27
+ allow(first_group_manager).to receive(:running?).and_return(true)
28
+ allow(second_group_manager).to receive(:running?).and_return(true)
29
+ end
30
+
31
+ describe '#healthy?' do
32
+ context 'when all groups have managers' do
33
+ context 'when all managers are running' do
34
+ it 'returns true' do
35
+ expect(subject.healthy?).to be true
36
+ end
37
+ end
38
+
39
+ context 'when one manager is not running' do
40
+ before do
41
+ allow(second_group_manager).to receive(:running?).and_return(false)
42
+ end
43
+
44
+ it 'returns false' do
45
+ expect(subject.healthy?).to be false
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when all groups do not have managers' do
51
+ before do
52
+ allow(second_group_manager).to receive(:group).and_return('some_random_group')
53
+ end
54
+
55
+ it 'returns false' do
56
+ expect(subject.healthy?).to be false
57
+ end
58
+ end
59
+ end
60
+ end
@@ -173,4 +173,26 @@ RSpec.describe Shoryuken::Manager do
173
173
  end
174
174
  end
175
175
  end
176
+
177
+ describe '#running?' do
178
+ context 'when the executor is running' do
179
+ before do
180
+ allow(executor).to receive(:running?).and_return(true)
181
+ end
182
+
183
+ it 'returns true' do
184
+ expect(subject.running?).to be true
185
+ end
186
+ end
187
+
188
+ context 'when the executor is not running' do
189
+ before do
190
+ allow(executor).to receive(:running?).and_return(false)
191
+ end
192
+
193
+ it 'returns false' do
194
+ expect(subject.running?).to be false
195
+ end
196
+ end
197
+ end
176
198
  end
@@ -1,4 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Shoryuken do
4
+ describe '.healthy?' do
5
+ before do
6
+ allow(Shoryuken::Runner).to receive(:instance).and_return(double(:instance, healthy?: :some_result))
7
+ end
8
+
9
+ it 'delegates to the runner instance' do
10
+ expect(described_class.healthy?).to eq(:some_result)
11
+ end
12
+ end
4
13
  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.2.3
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-30 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -174,6 +174,7 @@ files:
174
174
  - spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb
175
175
  - spec/shoryuken/extensions/active_job_wrapper_spec.rb
176
176
  - spec/shoryuken/fetcher_spec.rb
177
+ - spec/shoryuken/launcher_spec.rb
177
178
  - spec/shoryuken/manager_spec.rb
178
179
  - spec/shoryuken/middleware/chain_spec.rb
179
180
  - spec/shoryuken/middleware/server/auto_delete_spec.rb
@@ -231,6 +232,7 @@ test_files:
231
232
  - spec/shoryuken/extensions/active_job_concurrent_send_adapter_spec.rb
232
233
  - spec/shoryuken/extensions/active_job_wrapper_spec.rb
233
234
  - spec/shoryuken/fetcher_spec.rb
235
+ - spec/shoryuken/launcher_spec.rb
234
236
  - spec/shoryuken/manager_spec.rb
235
237
  - spec/shoryuken/middleware/chain_spec.rb
236
238
  - spec/shoryuken/middleware/server/auto_delete_spec.rb