sidekiq-limit_fetch 2.4.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq/limit_fetch/queues.rb +1 -1
- data/sidekiq-limit_fetch.gemspec +2 -2
- data/spec/sidekiq/extensions/queue_spec.rb +21 -21
- data/spec/sidekiq/limit_fetch/global/monitor_spec.rb +6 -6
- data/spec/sidekiq/limit_fetch/queues_spec.rb +33 -26
- data/spec/sidekiq/limit_fetch/semaphore_spec.rb +12 -12
- data/spec/sidekiq/limit_fetch_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1edc411f8e5b3ab852b0b005548a28fafd0167e4
|
4
|
+
data.tar.gz: df6b938724aa978eab9757d1c969c9577c9e58c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cb020c997e1dc814969e949ae497f49ee048f4d8b0b18833dd8eca51de0a1b943cae09d2e34e523e9d9c29b251101bf707cbab67d7a5ff270cda43be69ffbbd
|
7
|
+
data.tar.gz: 29eb71b1e70bde0da6dee13798e2fae39c2900abca6cbcf25d22ab2466028525ef84ff4abb3c00b02b48524b4ffef09bb8a98f432761d9e5081bf3a656c7d24e
|
data/sidekiq-limit_fetch.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'sidekiq-limit_fetch'
|
3
|
-
gem.version = '2.4.
|
3
|
+
gem.version = '2.4.2'
|
4
4
|
gem.license = 'MIT'
|
5
5
|
gem.authors = 'brainopia'
|
6
6
|
gem.email = 'brainopia@evilmartians.com'
|
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = %w(lib)
|
17
17
|
|
18
18
|
gem.add_dependency 'sidekiq', '>= 2.6.5', '< 4.0'
|
19
|
-
gem.add_development_dependency 'rspec', '
|
19
|
+
gem.add_development_dependency 'rspec', '~> 3.2.0'
|
20
20
|
gem.add_development_dependency 'rake'
|
21
21
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sidekiq::Queue do
|
3
|
+
RSpec.describe Sidekiq::Queue do
|
4
4
|
context 'singleton' do
|
5
5
|
shared_examples :constructor do
|
6
6
|
it 'with default name' do
|
7
7
|
new_object = -> { described_class.send constructor }
|
8
|
-
new_object.call.
|
8
|
+
expect(new_object.call).to eq new_object.call
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'with given name' do
|
12
12
|
new_object = ->(name) { described_class.send constructor, name }
|
13
|
-
new_object.call('name').
|
13
|
+
expect(new_object.call('name')).to eq new_object.call('name')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -29,67 +29,67 @@ describe Sidekiq::Queue do
|
|
29
29
|
let(:queue) { Sidekiq::Queue[name] }
|
30
30
|
|
31
31
|
it 'should be available' do
|
32
|
-
queue.acquire.
|
32
|
+
expect(queue.acquire).to be
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should be pausable' do
|
36
36
|
queue.pause
|
37
|
-
queue.acquire.
|
37
|
+
expect(queue.acquire).not_to be
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should be continuable' do
|
41
41
|
queue.pause
|
42
42
|
queue.unpause
|
43
|
-
queue.acquire.
|
43
|
+
expect(queue.acquire).to be
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should be limitable' do
|
47
47
|
queue.limit = 1
|
48
|
-
queue.acquire.
|
49
|
-
queue.acquire.
|
48
|
+
expect(queue.acquire).to be
|
49
|
+
expect(queue.acquire).not_to be
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should be resizable' do
|
53
53
|
queue.limit = 0
|
54
|
-
queue.acquire.
|
54
|
+
expect(queue.acquire).not_to be
|
55
55
|
queue.limit = nil
|
56
|
-
queue.acquire.
|
56
|
+
expect(queue.acquire).to be
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should be countable' do
|
60
60
|
queue.limit = 3
|
61
61
|
5.times { queue.acquire }
|
62
|
-
queue.probed.
|
62
|
+
expect(queue.probed).to eq 3
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'should be releasable' do
|
66
66
|
queue.acquire
|
67
|
-
queue.probed.
|
67
|
+
expect(queue.probed).to eq 1
|
68
68
|
queue.release
|
69
|
-
queue.probed.
|
69
|
+
expect(queue.probed).to eq 0
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should tell if paused' do
|
73
|
-
queue.
|
73
|
+
expect(queue).not_to be_paused
|
74
74
|
queue.pause
|
75
|
-
queue.
|
75
|
+
expect(queue).to be_paused
|
76
76
|
queue.unpause
|
77
|
-
queue.
|
77
|
+
expect(queue).not_to be_paused
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should tell if blocking' do
|
81
|
-
queue.
|
81
|
+
expect(queue).not_to be_blocking
|
82
82
|
queue.block
|
83
|
-
queue.
|
83
|
+
expect(queue).to be_blocking
|
84
84
|
queue.unblock
|
85
|
-
queue.
|
85
|
+
expect(queue).not_to be_blocking
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should be marked as changed' do
|
89
89
|
queue = Sidekiq::Queue["uniq_#{name}"]
|
90
|
-
queue.
|
90
|
+
expect(queue).not_to be_limit_changed
|
91
91
|
queue.limit = 3
|
92
|
-
queue.
|
92
|
+
expect(queue).to be_limit_changed
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
Thread.abort_on_exception = true
|
4
4
|
|
5
|
-
describe Sidekiq::LimitFetch::Global::Monitor do
|
5
|
+
RSpec.describe Sidekiq::LimitFetch::Global::Monitor do
|
6
6
|
let(:queues) { double dynamic?: false }
|
7
7
|
let(:monitor) { described_class.start! queues, ttl, timeout }
|
8
8
|
let(:ttl) { 1 }
|
@@ -23,21 +23,21 @@ describe Sidekiq::LimitFetch::Global::Monitor do
|
|
23
23
|
it 'should remove invalidated old locks' do
|
24
24
|
2.times { queue.acquire }
|
25
25
|
sleep 2*ttl
|
26
|
-
queue.probed.
|
26
|
+
expect(queue.probed).to eq 2
|
27
27
|
|
28
|
-
described_class.
|
28
|
+
allow(described_class).to receive(:update_heartbeat)
|
29
29
|
sleep 2*ttl
|
30
|
-
queue.probed.
|
30
|
+
expect(queue.probed).to eq 0
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should remove invalid locks' do
|
34
34
|
2.times { queue.acquire }
|
35
|
-
described_class.
|
35
|
+
allow(described_class).to receive(:update_heartbeat)
|
36
36
|
Sidekiq.redis do |it|
|
37
37
|
it.del Sidekiq::LimitFetch::Global::Monitor::PROCESS_SET
|
38
38
|
end
|
39
39
|
sleep 2*ttl
|
40
|
-
queue.probed.
|
40
|
+
expect(queue.probed).to eq 0
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -1,69 +1,71 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sidekiq::LimitFetch::Queues do
|
3
|
+
RSpec.describe Sidekiq::LimitFetch::Queues do
|
4
4
|
subject { described_class.new options }
|
5
5
|
|
6
|
-
let(:queues)
|
7
|
-
let(:limits)
|
8
|
-
let(:strict)
|
9
|
-
let(:blocking)
|
6
|
+
let(:queues) { %w[queue1 queue2] }
|
7
|
+
let(:limits) {{ 'queue1' => 3 }}
|
8
|
+
let(:strict) { true }
|
9
|
+
let(:blocking) {}
|
10
|
+
let(:process_limits) {{ 'queue2' => 3 }}
|
10
11
|
|
11
12
|
let(:options) do
|
12
13
|
{ queues: queues,
|
13
14
|
limits: limits,
|
14
15
|
strict: strict,
|
15
16
|
blocking: blocking,
|
17
|
+
process_limits: process_limits,
|
16
18
|
namespace: Sidekiq::LimitFetch::Redis.determine_namespace }
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'should acquire queues' do
|
20
22
|
subject.acquire
|
21
|
-
Sidekiq::Queue['queue1'].probed.
|
22
|
-
Sidekiq::Queue['queue2'].probed.
|
23
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 1
|
24
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
23
25
|
end
|
24
26
|
|
25
27
|
it 'should acquire dynamically blocking queues' do
|
26
28
|
subject.acquire
|
27
|
-
Sidekiq::Queue['queue1'].probed.
|
28
|
-
Sidekiq::Queue['queue2'].probed.
|
29
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 1
|
30
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
29
31
|
|
30
32
|
Sidekiq::Queue['queue1'].block
|
31
33
|
|
32
34
|
subject.acquire
|
33
|
-
Sidekiq::Queue['queue1'].probed.
|
34
|
-
Sidekiq::Queue['queue2'].probed.
|
35
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 2
|
36
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'should block except given queues' do
|
38
40
|
Sidekiq::Queue['queue1'].block_except 'queue2'
|
39
41
|
subject.acquire
|
40
|
-
Sidekiq::Queue['queue1'].probed.
|
41
|
-
Sidekiq::Queue['queue2'].probed.
|
42
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 1
|
43
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
42
44
|
|
43
45
|
Sidekiq::Queue['queue1'].block_except 'queue404'
|
44
46
|
subject.acquire
|
45
|
-
Sidekiq::Queue['queue1'].probed.
|
46
|
-
Sidekiq::Queue['queue2'].probed.
|
47
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 2
|
48
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'should release queues' do
|
50
52
|
subject.acquire
|
51
53
|
subject.release_except nil
|
52
|
-
Sidekiq::Queue['queue1'].probed.
|
53
|
-
Sidekiq::Queue['queue2'].probed.
|
54
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 0
|
55
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 0
|
54
56
|
end
|
55
57
|
|
56
58
|
it 'should release queues except selected' do
|
57
59
|
subject.acquire
|
58
60
|
subject.release_except 'queue:queue1'
|
59
|
-
Sidekiq::Queue['queue1'].probed.
|
60
|
-
Sidekiq::Queue['queue2'].probed.
|
61
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 1
|
62
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 0
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'should release when no queues was acquired' do
|
64
66
|
queues.each {|name| Sidekiq::Queue[name].pause }
|
65
67
|
subject.acquire
|
66
|
-
|
68
|
+
expect { subject.release_except nil }.not_to raise_exception
|
67
69
|
end
|
68
70
|
|
69
71
|
context 'blocking' do
|
@@ -71,26 +73,31 @@ describe Sidekiq::LimitFetch::Queues do
|
|
71
73
|
|
72
74
|
it 'should acquire blocking queues' do
|
73
75
|
3.times { subject.acquire }
|
74
|
-
Sidekiq::Queue['queue1'].probed.
|
75
|
-
Sidekiq::Queue['queue2'].probed.
|
76
|
+
expect(Sidekiq::Queue['queue1'].probed).to eq 3
|
77
|
+
expect(Sidekiq::Queue['queue2'].probed).to eq 1
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
81
|
it 'should set limits' do
|
80
82
|
subject
|
81
|
-
Sidekiq::Queue['queue1'].limit.
|
82
|
-
Sidekiq::Queue['queue2'].limit.
|
83
|
+
expect(Sidekiq::Queue['queue1'].limit).to eq 3
|
84
|
+
expect(Sidekiq::Queue['queue2'].limit).not_to be
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should set process_limits' do
|
88
|
+
subject
|
89
|
+
expect(Sidekiq::Queue['queue2'].process_limit).to eq 3
|
83
90
|
end
|
84
91
|
|
85
92
|
context 'without strict flag' do
|
86
93
|
let(:strict) { false }
|
87
94
|
|
88
95
|
it 'should retrieve weighted queues' do
|
89
|
-
subject.ordered_queues.
|
96
|
+
expect(subject.ordered_queues).to match_array(%w(queue1 queue2))
|
90
97
|
end
|
91
98
|
end
|
92
99
|
|
93
100
|
it 'with strict flag should retrieve strictly ordered queues' do
|
94
|
-
subject.ordered_queues.
|
101
|
+
expect(subject.ordered_queues).to eq %w(queue1 queue2)
|
95
102
|
end
|
96
103
|
end
|
@@ -1,48 +1,48 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'semaphore' do
|
3
|
+
RSpec.describe 'semaphore' do
|
4
4
|
let(:name) { 'default' }
|
5
5
|
subject { Sidekiq::LimitFetch::Global::Semaphore.new name }
|
6
6
|
|
7
7
|
it 'should have no limit by default' do
|
8
|
-
subject.limit.
|
8
|
+
expect(subject.limit).not_to be
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should set limit' do
|
12
12
|
subject.limit = 4
|
13
|
-
subject.limit.
|
13
|
+
expect(subject.limit).to eq 4
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should acquire and count active tasks' do
|
17
17
|
3.times { subject.acquire }
|
18
|
-
subject.probed.
|
18
|
+
expect(subject.probed).to eq 3
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should acquire tasks with regard to limit' do
|
22
22
|
subject.limit = 4
|
23
23
|
6.times { subject.acquire }
|
24
|
-
subject.probed.
|
24
|
+
expect(subject.probed).to eq 4
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should acquire tasks with regard to process limit' do
|
28
28
|
subject.process_limit = 4
|
29
29
|
6.times { subject.acquire }
|
30
|
-
subject.probed.
|
30
|
+
expect(subject.probed).to eq 4
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should release active tasks' do
|
34
34
|
6.times { subject.acquire }
|
35
35
|
3.times { subject.release }
|
36
|
-
subject.probed.
|
36
|
+
expect(subject.probed).to eq 3
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should pause tasks' do
|
40
40
|
3.times { subject.acquire }
|
41
41
|
subject.pause
|
42
42
|
2.times { subject.acquire }
|
43
|
-
subject.probed.
|
43
|
+
expect(subject.probed).to eq 3
|
44
44
|
2.times { subject.release }
|
45
|
-
subject.probed.
|
45
|
+
expect(subject.probed).to eq 1
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should unpause tasks' do
|
@@ -50,16 +50,16 @@ describe 'semaphore' do
|
|
50
50
|
3.times { subject.acquire }
|
51
51
|
subject.unpause
|
52
52
|
2.times { subject.acquire }
|
53
|
-
subject.probed.
|
53
|
+
expect(subject.probed).to eq 2
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should pause tasks for a limited time' do
|
57
57
|
3.times { subject.acquire }
|
58
58
|
subject.pause_for_ms 50
|
59
59
|
2.times { subject.acquire }
|
60
|
-
subject.probed.
|
60
|
+
expect(subject.probed).to eq 3
|
61
61
|
sleep(100.0 / 1000)
|
62
62
|
2.times { subject.acquire }
|
63
|
-
subject.probed.
|
63
|
+
expect(subject.probed).to eq 5
|
64
64
|
end
|
65
65
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Sidekiq::LimitFetch do
|
3
|
+
RSpec.describe Sidekiq::LimitFetch do
|
4
4
|
before :each do
|
5
5
|
Sidekiq.redis do |it|
|
6
6
|
it.del 'queue:queue1'
|
@@ -17,31 +17,31 @@ describe Sidekiq::LimitFetch do
|
|
17
17
|
|
18
18
|
it 'should acquire lock on queue for execution' do
|
19
19
|
work = subject.retrieve_work
|
20
|
-
work.queue_name.
|
21
|
-
work.message.
|
20
|
+
expect(work.queue_name).to eq 'queue1'
|
21
|
+
expect(work.message).to eq 'task1'
|
22
22
|
|
23
|
-
Sidekiq::Queue['queue1'].busy.
|
24
|
-
Sidekiq::Queue['queue2'].busy.
|
23
|
+
expect(Sidekiq::Queue['queue1'].busy).to eq 1
|
24
|
+
expect(Sidekiq::Queue['queue2'].busy).to eq 0
|
25
25
|
|
26
|
-
subject.retrieve_work.
|
26
|
+
expect(subject.retrieve_work).not_to be
|
27
27
|
work.requeue
|
28
28
|
|
29
|
-
Sidekiq::Queue['queue1'].busy.
|
30
|
-
Sidekiq::Queue['queue2'].busy.
|
29
|
+
expect(Sidekiq::Queue['queue1'].busy).to eq 0
|
30
|
+
expect(Sidekiq::Queue['queue2'].busy).to eq 0
|
31
31
|
|
32
32
|
work = subject.retrieve_work
|
33
|
-
work.message.
|
33
|
+
expect(work.message).to eq 'task1'
|
34
34
|
|
35
|
-
Sidekiq::Queue['queue1'].busy.
|
36
|
-
Sidekiq::Queue['queue2'].busy.
|
35
|
+
expect(Sidekiq::Queue['queue1'].busy).to eq 1
|
36
|
+
expect(Sidekiq::Queue['queue2'].busy).to eq 0
|
37
37
|
|
38
|
-
subject.retrieve_work.
|
38
|
+
expect(subject.retrieve_work).not_to be
|
39
39
|
work.acknowledge
|
40
40
|
|
41
|
-
Sidekiq::Queue['queue1'].busy.
|
42
|
-
Sidekiq::Queue['queue2'].busy.
|
41
|
+
expect(Sidekiq::Queue['queue1'].busy).to eq 0
|
42
|
+
expect(Sidekiq::Queue['queue2'].busy).to eq 0
|
43
43
|
|
44
44
|
work = subject.retrieve_work
|
45
|
-
work.message.
|
45
|
+
expect(work.message).to eq 'task2'
|
46
46
|
end
|
47
47
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,9 @@ Sidekiq.logger = nil
|
|
6
6
|
Sidekiq.redis = { namespace: ENV['namespace'] }
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
|
+
config.order = :random
|
10
|
+
config.disable_monkey_patching!
|
11
|
+
config.raise_errors_for_deprecations!
|
9
12
|
config.before :each do
|
10
13
|
Sidekiq::Queue.reset_instances!
|
11
14
|
Sidekiq.redis do |it|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-limit_fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brainopia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -34,16 +34,16 @@ dependencies:
|
|
34
34
|
name: rspec
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 3.2.0
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 3.2.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|