shoryuken 4.0.2 → 4.0.3
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 +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -0
- data/lib/shoryuken/environment_loader.rb +3 -2
- data/lib/shoryuken/launcher.rb +1 -1
- data/lib/shoryuken/options.rb +10 -3
- data/lib/shoryuken/polling/base.rb +1 -3
- data/lib/shoryuken/polling/strict_priority.rb +2 -1
- data/lib/shoryuken/polling/weighted_round_robin.rb +2 -1
- data/lib/shoryuken/version.rb +1 -1
- data/spec/shoryuken/environment_loader_spec.rb +24 -1
- data/spec/shoryuken/options_spec.rb +17 -1
- data/spec/shoryuken/polling/strict_priority_spec.rb +8 -0
- data/spec/shoryuken/polling/weighted_round_robin_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd77c85674d135c91607fd5d422af325a2eea48b6e6bd7039b0d2c63cd6f0094
|
4
|
+
data.tar.gz: 41909fd74b45cc2dbb3c1cfced6717299e0819e960210c741d3c468e8f4fa569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e10d6ca93d95bd1fccd6da3dd05df596db6fc5613a5a7d56c83ff6bb3db08202780939fd847d4a54db932f289a553706e8290ead58a174b982f036b524c8b46
|
7
|
+
data.tar.gz: 5abaac5fdd7c5c5ea1e512ee13757a25491da1c8999e3fc8001b9d5465023e511d7754224d684f1c7b16014c85d9019533bec86d1740fe0da54c7d9d4b97adab
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -122,7 +122,7 @@ module Shoryuken
|
|
122
122
|
|
123
123
|
def parse_queues
|
124
124
|
if Shoryuken.options[:queues].to_a.any?
|
125
|
-
Shoryuken.add_group('default', Shoryuken.options
|
125
|
+
Shoryuken.add_group('default', Shoryuken.options[:concurrency])
|
126
126
|
|
127
127
|
Shoryuken.options[:queues].to_a.each do |queue, weight|
|
128
128
|
parse_queue(queue, weight, 'default')
|
@@ -130,7 +130,8 @@ module Shoryuken
|
|
130
130
|
end
|
131
131
|
|
132
132
|
Shoryuken.options[:groups].to_a.each do |group, options|
|
133
|
-
Shoryuken.add_group(group, options
|
133
|
+
Shoryuken.add_group(group, options[:concurrency], delay: options[:delay])
|
134
|
+
|
134
135
|
options[:queues].to_a.each do |queue, weight|
|
135
136
|
parse_queue(queue, weight, group)
|
136
137
|
end
|
data/lib/shoryuken/launcher.rb
CHANGED
@@ -72,7 +72,7 @@ module Shoryuken
|
|
72
72
|
Shoryuken.groups.map do |group, options|
|
73
73
|
Shoryuken::Manager.new(
|
74
74
|
Shoryuken::Fetcher.new(group),
|
75
|
-
Shoryuken.polling_strategy(group).new(options[:queues]),
|
75
|
+
Shoryuken.polling_strategy(group).new(options[:queues], Shoryuken::Options.delay(group)),
|
76
76
|
options[:concurrency],
|
77
77
|
executor
|
78
78
|
)
|
data/lib/shoryuken/options.rb
CHANGED
@@ -4,7 +4,7 @@ module Shoryuken
|
|
4
4
|
concurrency: 25,
|
5
5
|
queues: [],
|
6
6
|
aws: {},
|
7
|
-
delay: 0,
|
7
|
+
delay: 0.0,
|
8
8
|
timeout: 8,
|
9
9
|
lifecycle_events: {
|
10
10
|
startup: [],
|
@@ -30,9 +30,13 @@ module Shoryuken
|
|
30
30
|
defined?(::ActiveJob)
|
31
31
|
end
|
32
32
|
|
33
|
-
def add_group(group, concurrency)
|
33
|
+
def add_group(group, concurrency = nil, delay: nil)
|
34
|
+
concurrency ||= options[:concurrency]
|
35
|
+
delay ||= options[:delay]
|
36
|
+
|
34
37
|
groups[group] ||= {
|
35
38
|
concurrency: concurrency,
|
39
|
+
delay: delay,
|
36
40
|
queues: []
|
37
41
|
}
|
38
42
|
end
|
@@ -77,7 +81,6 @@ module Shoryuken
|
|
77
81
|
|
78
82
|
def polling_strategy(group)
|
79
83
|
strategy = (group == 'default' ? options : options[:groups].to_h[group]).to_h[:polling_strategy]
|
80
|
-
|
81
84
|
case strategy
|
82
85
|
when 'WeightedRoundRobin', nil # Default case
|
83
86
|
Polling::WeightedRoundRobin
|
@@ -90,6 +93,10 @@ module Shoryuken
|
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
96
|
+
def delay(group)
|
97
|
+
groups[group].to_h.fetch(:delay, options[:delay]).to_f
|
98
|
+
end
|
99
|
+
|
93
100
|
def start_callback
|
94
101
|
@@start_callback
|
95
102
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Shoryuken
|
2
2
|
module Polling
|
3
3
|
class StrictPriority < BaseStrategy
|
4
|
-
def initialize(queues)
|
4
|
+
def initialize(queues, delay = nil)
|
5
5
|
# Priority ordering of the queues, highest priority first
|
6
6
|
@queues = queues
|
7
7
|
.group_by { |q| q }
|
@@ -12,6 +12,7 @@ module Shoryuken
|
|
12
12
|
@paused_until = queues
|
13
13
|
.each_with_object({}) { |queue, h| h[queue] = Time.at(0) }
|
14
14
|
|
15
|
+
@delay = delay
|
15
16
|
# Start queues at 0
|
16
17
|
reset_next_queue
|
17
18
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Shoryuken
|
2
2
|
module Polling
|
3
3
|
class WeightedRoundRobin < BaseStrategy
|
4
|
-
def initialize(queues)
|
4
|
+
def initialize(queues, delay = nil)
|
5
5
|
@initial_queues = queues
|
6
6
|
@queues = queues.dup.uniq
|
7
7
|
@paused_queues = []
|
8
|
+
@delay = delay
|
8
9
|
end
|
9
10
|
|
10
11
|
def next_queue
|
data/lib/shoryuken/version.rb
CHANGED
@@ -4,7 +4,7 @@ require 'active_job'
|
|
4
4
|
RSpec.describe Shoryuken::EnvironmentLoader do
|
5
5
|
subject { described_class.new({}) }
|
6
6
|
|
7
|
-
describe '#parse_queues' do
|
7
|
+
describe '#parse_queues loads default queues' do
|
8
8
|
before do
|
9
9
|
allow(subject).to receive(:load_rails)
|
10
10
|
allow(subject).to receive(:prefix_active_job_queue_names)
|
@@ -22,6 +22,29 @@ RSpec.describe Shoryuken::EnvironmentLoader do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe '#parse_queues includes delay per groups' do
|
26
|
+
before do
|
27
|
+
allow(subject).to receive(:load_rails)
|
28
|
+
allow(subject).to receive(:prefix_active_job_queue_names)
|
29
|
+
allow(subject).to receive(:require_workers)
|
30
|
+
allow(subject).to receive(:validate_queues)
|
31
|
+
allow(subject).to receive(:validate_workers)
|
32
|
+
allow(subject).to receive(:patch_deprecated_workers)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify do
|
36
|
+
Shoryuken.options[:queues] = ['queue1', 'queue2'] # default queues
|
37
|
+
Shoryuken.options[:groups] = [[ 'custom', { queues: ['queue3'], delay: 25 }]]
|
38
|
+
subject.load
|
39
|
+
|
40
|
+
expect(Shoryuken.groups['default'][:queues]).to eq(%w[queue1 queue2])
|
41
|
+
expect(Shoryuken.groups['default'][:delay]).to eq(Shoryuken.options[:delay])
|
42
|
+
expect(Shoryuken.groups['custom'][:queues]).to eq(%w[queue3])
|
43
|
+
expect(Shoryuken.groups['custom'][:delay]).to eq(25)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
25
48
|
describe '#prefix_active_job_queue_names' do
|
26
49
|
before do
|
27
50
|
allow(subject).to receive(:load_rails)
|
@@ -1,19 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Shoryuken::Options do
|
4
|
-
describe '.add_group' do
|
4
|
+
describe '.add_group adds queues and optional delay' do
|
5
5
|
before do
|
6
6
|
Shoryuken.groups.clear
|
7
7
|
Shoryuken.add_group('group1', 25)
|
8
8
|
Shoryuken.add_group('group2', 25)
|
9
|
+
Shoryuken.add_group('group3', 25, delay: 5)
|
9
10
|
end
|
10
11
|
|
11
12
|
specify do
|
12
13
|
described_class.add_queue('queue1', 1, 'group1')
|
13
14
|
described_class.add_queue('queue2', 2, 'group2')
|
15
|
+
described_class.add_queue('queue3', 1, 'group3')
|
14
16
|
|
15
17
|
expect(described_class.groups['group1'][:queues]).to eq(%w[queue1])
|
16
18
|
expect(described_class.groups['group2'][:queues]).to eq(%w[queue2 queue2])
|
19
|
+
expect(described_class.groups['group3'][:queues]).to eq(%w[queue3])
|
20
|
+
expect(described_class.groups['group3'][:delay]).to eq(5)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.delay works for each group' do
|
25
|
+
specify do
|
26
|
+
Shoryuken.add_group('group1', 25)
|
27
|
+
Shoryuken.add_group('group2', 25, delay: 5)
|
28
|
+
described_class.add_queue('queue1', 1, 'group1')
|
29
|
+
described_class.add_queue('queue2', 2, 'group2')
|
30
|
+
|
31
|
+
expect(described_class.delay('group1')).to eq(Shoryuken.options[:delay])
|
32
|
+
expect(described_class.delay('group2')).to eq(5.0)
|
17
33
|
end
|
18
34
|
end
|
19
35
|
|
@@ -86,6 +86,14 @@ RSpec.describe Shoryuken::Polling::StrictPriority do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
describe '#delay' do
|
90
|
+
it 'sets delay based on group' do
|
91
|
+
delay_polling = Shoryuken::Polling::StrictPriority.new(queues, 25)
|
92
|
+
expect(delay_polling.delay).to eq(25.0)
|
93
|
+
expect(subject.delay).to eq(1.0)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
89
97
|
describe '#messages_found' do
|
90
98
|
it 'pauses a queue if there are no messages found' do
|
91
99
|
# [shoryuken, 2]
|
@@ -96,4 +96,12 @@ RSpec.describe Shoryuken::Polling::WeightedRoundRobin do
|
|
96
96
|
expect(subject.instance_variable_get(:@queues)).to eq([queue1, queue2, queue1])
|
97
97
|
end
|
98
98
|
end
|
99
|
+
|
100
|
+
describe '#delay' do
|
101
|
+
it 'sets delay based on group' do
|
102
|
+
delay_polling = Shoryuken::Polling::WeightedRoundRobin.new(queues, 25)
|
103
|
+
expect(delay_polling.delay).to eq(25.0)
|
104
|
+
expect(subject.delay).to eq(1.0)
|
105
|
+
end
|
106
|
+
end
|
99
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -43,7 +43,7 @@ RSpec.configure do |config|
|
|
43
43
|
Shoryuken.groups.clear
|
44
44
|
|
45
45
|
Shoryuken.options[:concurrency] = 1
|
46
|
-
Shoryuken.options[:delay] = 1
|
46
|
+
Shoryuken.options[:delay] = 1.0
|
47
47
|
Shoryuken.options[:timeout] = 1
|
48
48
|
Shoryuken.options[:daemon] = nil
|
49
49
|
Shoryuken.options[:logfile] = nil
|
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: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Cantero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -227,8 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
|
-
|
231
|
-
rubygems_version: 2.5.2
|
230
|
+
rubygems_version: 3.0.1
|
232
231
|
signing_key:
|
233
232
|
specification_version: 4
|
234
233
|
summary: Shoryuken is a super efficient AWS SQS thread based message processor
|