sidekiq-throttler 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8acf1d69eb8a5045cdff1273d3f44342845cfc9b
4
- data.tar.gz: 0ca683c9e8cf5149d430391ec1bd85488f3517b9
3
+ metadata.gz: 19e1d69fd9be458ce6356483854f19513b01e5e7
4
+ data.tar.gz: 1c0582120520cfa48ce066cf410f7d48c492a394
5
5
  SHA512:
6
- metadata.gz: 347d780d00c2c9a538c79e0bb48f3977f037d3bd70fbce3a63a24557aa01a92b350a5d80d00fe9fc79985f3c50c7603de6c080ff518380d7ac894066492c9453
7
- data.tar.gz: 17003989b18787321d19f939ef07f8a165aa325fd7a63c79561dd5a40eaf50087fcf96450439cbdf6a95c87c00f7bf3f52cc67c3e081568b0d298fe08084c4e3
6
+ metadata.gz: 35a019db24bfd3833fa22edfed15b00b144b9a73966de3b9c075f794b832ba7e4cf4791f633f8432cc35ad21e9ace738d94635268c5b0109b6c866dc1d68832f
7
+ data.tar.gz: 1d74ed077c71d2ff8630d0286958a2869ca3bb4a83e6f3b5fa74f967cfbf7312ae05150176b14f34883fb827ea7bad5438527f138afb8ee8a6530e3a0542406a
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format nested
1
+ --format documentation
2
2
  --color
data/.travis.yml CHANGED
@@ -13,3 +13,6 @@ notifications:
13
13
  email:
14
14
  recipients:
15
15
  - gabe@ga.be
16
+ gemfile:
17
+ - gemfiles/sidekiq_2.gemfile
18
+ - gemfiles/sidekiq_master.gemfile
data/Appraisals CHANGED
@@ -2,6 +2,6 @@ appraise 'sidekiq-2' do
2
2
  gem 'sidekiq', '2.17.7'
3
3
  end
4
4
 
5
- appraise 'sidekiq-head' do
5
+ appraise 'sidekiq-master' do
6
6
  gem 'sidekiq', github: 'mperham/sidekiq'
7
7
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 0.4.1 (June 18, 2014)
2
+
3
+ * Dependency lock is loosened further for compatibility with Sidekiq 3.x.
4
+
5
+ *Gabe Evans*
6
+
7
+ * Appraisal is used for continous integration with Sidekiq 2.x and Sidekiq's
8
+ master branch.
9
+
10
+ *Gabe Evans*
11
+
12
+ * Specs now use RSpec 3 and the `expect()` syntax.
13
+
14
+ *Gabe Evans*
15
+
1
16
  ## 0.4.0 (April 24, 2014)
2
17
 
3
18
  * Now supports using a Proc for `:period` option.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sidekiq-throttler.gemspec
4
4
  gemspec
5
+
6
+ gem 'appraisal', '~> 1.0.0'
data/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/gevans/sidekiq-throttler.png)](http://travis-ci.org/gevans/sidekiq-throttler)
4
4
  [![Dependency Status](https://gemnasium.com/gevans/sidekiq-throttler.png)](https://gemnasium.com/gevans/sidekiq-throttler)
5
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-throttler.svg)](http://badge.fury.io/rb/sidekiq-throttler)
5
6
 
6
7
  Sidekiq::Throttler is a middleware for Sidekiq that adds the ability to rate
7
8
  limit job execution on a per-worker basis.
8
9
 
9
10
  ## Compatibility
10
11
 
11
- Sidekiq::Throttler is actively tested against MRI versions 2.0.0 and 1.9.3.
12
+ Sidekiq::Throttler is actively tested against MRI versions 2.1.1, 2.1.0, 2.0.0,
13
+ and 1.9.3.
12
14
 
13
15
  ## Installation
14
16
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "appraisal", "~> 1.0.0"
5
6
  gem "sidekiq", "2.17.7"
6
7
 
7
- gemspec :path=>"../"
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0"
6
+ gem "sidekiq", :github => "mperham/sidekiq"
7
+
8
+ gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  class Throttler
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -19,9 +19,8 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = %w(lib)
20
20
 
21
21
  gem.add_dependency 'activesupport'
22
- gem.add_dependency 'sidekiq', '>= 2.5', '< 3.1'
22
+ gem.add_dependency 'sidekiq', '>= 2.5', '< 4.0'
23
23
 
24
- gem.add_development_dependency 'appraisal', '~> 0.5'
25
24
  gem.add_development_dependency 'growl'
26
25
  gem.add_development_dependency 'guard'
27
26
  gem.add_development_dependency 'guard-bundler'
@@ -19,7 +19,7 @@ shared_examples "incrementing" do
19
19
  rate_limit.increment
20
20
  end
21
21
 
22
- rate_limit.count.should eq(5)
22
+ expect(rate_limit.count).to eq(5)
23
23
  end
24
24
  end
25
25
  end
@@ -53,15 +53,15 @@ describe Sidekiq::Throttler::RateLimit do
53
53
  describe '.new' do
54
54
 
55
55
  it 'initializes with a provided worker' do
56
- rate_limit.worker.should eq(worker)
56
+ expect(rate_limit.worker).to eq(worker)
57
57
  end
58
58
 
59
59
  it 'initializes with provided payload' do
60
- rate_limit.payload.should eq(payload)
60
+ expect(rate_limit.payload).to eq(payload)
61
61
  end
62
62
 
63
63
  it 'initializes with a provided queue' do
64
- rate_limit.queue.should eq('meow')
64
+ expect(rate_limit.queue).to eq('meow')
65
65
  end
66
66
 
67
67
  context "with an invalid storage backend" do
@@ -76,17 +76,17 @@ describe Sidekiq::Throttler::RateLimit do
76
76
  describe '#options' do
77
77
 
78
78
  it 'retrieves throttle options from the worker' do
79
- worker_class.get_sidekiq_options.should_receive(:[]).with('throttle')
79
+ expect(worker_class.get_sidekiq_options).to receive(:[]).with('throttle')
80
80
  rate_limit.options
81
81
  end
82
82
 
83
83
  it 'stringifies the option keys' do
84
- worker_class.get_sidekiq_options['throttle'].should_receive(:stringify_keys)
84
+ expect(worker_class.get_sidekiq_options['throttle']).to receive(:stringify_keys)
85
85
  rate_limit.options
86
86
  end
87
87
 
88
88
  it 'caches the returned options' do
89
- rate_limit.options.object_id.should eq(rate_limit.options.object_id)
89
+ expect(rate_limit.options.object_id).to eq(rate_limit.options.object_id)
90
90
  end
91
91
 
92
92
  context 'when the worker specifies no throttle options' do
@@ -98,7 +98,7 @@ describe Sidekiq::Throttler::RateLimit do
98
98
  end
99
99
 
100
100
  it 'returns an empty hash' do
101
- rate_limit.options.should eq({})
101
+ expect(rate_limit.options).to eq({})
102
102
  end
103
103
  end
104
104
  end
@@ -115,22 +115,22 @@ describe Sidekiq::Throttler::RateLimit do
115
115
  end
116
116
 
117
117
  it 'returns the result of the called Proc' do
118
- rate_limit.threshold.should eq(500)
118
+ expect(rate_limit.threshold).to eq(500)
119
119
  end
120
120
  end
121
121
 
122
122
  it 'retrieves the threshold from #options' do
123
123
  rate_limit.options['threshold'] = 26
124
- rate_limit.threshold.should eq(26)
124
+ expect(rate_limit.threshold).to eq(26)
125
125
  end
126
126
 
127
127
  it 'converts the threshold to an integer' do
128
128
  rate_limit.options['threshold'] = '33'
129
- rate_limit.threshold.should be_a(Integer)
129
+ expect(rate_limit.threshold).to be_a(Integer)
130
130
  end
131
131
 
132
132
  it 'caches the returned integer' do
133
- rate_limit.threshold.object_id.should eq(rate_limit.threshold.object_id)
133
+ expect(rate_limit.threshold.object_id).to eq(rate_limit.threshold.object_id)
134
134
  end
135
135
  end
136
136
 
@@ -146,22 +146,22 @@ describe Sidekiq::Throttler::RateLimit do
146
146
  end
147
147
 
148
148
  it 'returns the result of the called Proc' do
149
- rate_limit.period.should eq(60)
149
+ expect(rate_limit.period).to eq(60)
150
150
  end
151
151
  end
152
152
 
153
153
  it 'retrieves the period from #options' do
154
154
  rate_limit.options['period'] = 10.0
155
- rate_limit.period.should eq(10.0)
155
+ expect(rate_limit.period).to eq(10.0)
156
156
  end
157
157
 
158
158
  it 'converts the period to a float' do
159
159
  rate_limit.options['period'] = 27
160
- rate_limit.period.should be_a(Float)
160
+ expect(rate_limit.period).to be_a(Float)
161
161
  end
162
162
 
163
163
  it 'caches the returned float' do
164
- rate_limit.period.object_id.should eq(rate_limit.period.object_id)
164
+ expect(rate_limit.period.object_id).to eq(rate_limit.period.object_id)
165
165
  end
166
166
  end
167
167
 
@@ -172,13 +172,13 @@ describe Sidekiq::Throttler::RateLimit do
172
172
  end
173
173
 
174
174
  it 'caches the key from the worker' do
175
- rate_limit.key.object_id.should eq(rate_limit.key.object_id)
175
+ expect(rate_limit.key.object_id).to eq(rate_limit.key.object_id)
176
176
  end
177
177
 
178
178
  context 'when key is a string' do
179
179
 
180
180
  it 'returns the key as a symbol' do
181
- rate_limit.key.should eq('winning')
181
+ expect(rate_limit.key).to eq('winning')
182
182
  end
183
183
  end
184
184
 
@@ -193,7 +193,7 @@ describe Sidekiq::Throttler::RateLimit do
193
193
  end
194
194
 
195
195
  it 'returns the result of the called Proc' do
196
- rate_limit.key.should eq('wat:is:this')
196
+ expect(rate_limit.key).to eq('wat:is:this')
197
197
  end
198
198
  end
199
199
  end
@@ -203,7 +203,7 @@ describe Sidekiq::Throttler::RateLimit do
203
203
  context 'when options are correctly specified' do
204
204
 
205
205
  it 'returns true' do
206
- rate_limit.can_throttle?.should be_true
206
+ expect(rate_limit.can_throttle?).to be_truthy
207
207
  end
208
208
  end
209
209
 
@@ -212,8 +212,8 @@ describe Sidekiq::Throttler::RateLimit do
212
212
  context "when ##{method} is zero" do
213
213
 
214
214
  it 'returns false' do
215
- rate_limit.stub(method.to_sym).and_return(0)
216
- rate_limit.can_throttle?.should be_false
215
+ allow(rate_limit).to receive(method.to_sym).and_return(0)
216
+ expect(rate_limit.can_throttle?).to be_falsey
217
217
  end
218
218
  end
219
219
  end
@@ -224,24 +224,24 @@ describe Sidekiq::Throttler::RateLimit do
224
224
  context 'when #count is equal to #threshold' do
225
225
 
226
226
  it 'returns true' do
227
- rate_limit.should_receive(:count).and_return(rate_limit.threshold)
228
- rate_limit.should be_exceeded
227
+ expect(rate_limit).to receive(:count).and_return(rate_limit.threshold)
228
+ expect(rate_limit).to be_exceeded
229
229
  end
230
230
  end
231
231
 
232
232
  context 'when #count is greater than #threshold' do
233
233
 
234
234
  it 'returns true' do
235
- rate_limit.should_receive(:count).and_return(rate_limit.threshold + 1)
236
- rate_limit.should be_exceeded
235
+ expect(rate_limit).to receive(:count).and_return(rate_limit.threshold + 1)
236
+ expect(rate_limit).to be_exceeded
237
237
  end
238
238
  end
239
239
 
240
240
  context 'when #count is less than #threshold' do
241
241
 
242
242
  it 'returns false' do
243
- rate_limit.should_receive(:count).and_return(0)
244
- rate_limit.should_not be_exceeded
243
+ expect(rate_limit).to receive(:count).and_return(0)
244
+ expect(rate_limit).not_to be_exceeded
245
245
  end
246
246
  end
247
247
  end
@@ -249,10 +249,10 @@ describe Sidekiq::Throttler::RateLimit do
249
249
  describe '#within_bounds?' do
250
250
 
251
251
  it 'returns the opposite of #exceeded?' do
252
- rate_limit.should_receive(:exceeded?).and_return(true)
253
- rate_limit.should_not be_within_bounds
254
- rate_limit.should_receive(:exceeded?).and_return(false)
255
- rate_limit.should be_within_bounds
252
+ expect(rate_limit).to receive(:exceeded?).and_return(true)
253
+ expect(rate_limit).not_to be_within_bounds
254
+ expect(rate_limit).to receive(:exceeded?).and_return(false)
255
+ expect(rate_limit).to be_within_bounds
256
256
  end
257
257
  end
258
258
 
@@ -275,12 +275,12 @@ describe Sidekiq::Throttler::RateLimit do
275
275
  context 'when rate limit cannot be throttled' do
276
276
 
277
277
  before do
278
- rate_limit.should_receive(:can_throttle?).and_return(false)
278
+ expect(rate_limit).to receive(:can_throttle?).and_return(false)
279
279
  end
280
280
 
281
281
  it 'calls the within bounds callback' do
282
282
  callback = Proc.new {}
283
- callback.should_receive(:call)
283
+ expect(callback).to receive(:call)
284
284
 
285
285
  rate_limit.within_bounds(&callback)
286
286
  rate_limit.execute
@@ -289,7 +289,7 @@ describe Sidekiq::Throttler::RateLimit do
289
289
  it 'does not increment the counter' do
290
290
  rate_limit.within_bounds {}
291
291
 
292
- rate_limit.should_not_receive(:increment)
292
+ expect(rate_limit).not_to receive(:increment)
293
293
  rate_limit.execute
294
294
  end
295
295
  end
@@ -297,12 +297,12 @@ describe Sidekiq::Throttler::RateLimit do
297
297
  context 'when rate limit is exceeded' do
298
298
 
299
299
  before do
300
- rate_limit.should_receive(:exceeded?).and_return(true)
300
+ expect(rate_limit).to receive(:exceeded?).and_return(true)
301
301
  end
302
302
 
303
303
  it 'calls the exceeded callback with the configured #period' do
304
304
  callback = Proc.new {}
305
- callback.should_receive(:call).with(rate_limit.period)
305
+ expect(callback).to receive(:call).with(rate_limit.period)
306
306
 
307
307
  rate_limit.exceeded(&callback)
308
308
  rate_limit.execute
@@ -314,13 +314,13 @@ describe Sidekiq::Throttler::RateLimit do
314
314
  it 'increments the counter' do
315
315
  rate_limit.within_bounds {}
316
316
 
317
- rate_limit.should_receive(:increment)
317
+ expect(rate_limit).to receive(:increment)
318
318
  rate_limit.execute
319
319
  end
320
320
 
321
321
  it 'calls the within bounds callback' do
322
322
  callback = Proc.new {}
323
- callback.should_receive(:call)
323
+ expect(callback).to receive(:call)
324
324
 
325
325
  rate_limit.within_bounds(&callback)
326
326
  rate_limit.execute
@@ -333,7 +333,7 @@ describe Sidekiq::Throttler::RateLimit do
333
333
  context 'when no jobs have executed' do
334
334
 
335
335
  it 'returns 0' do
336
- rate_limit.count.should be_zero
336
+ expect(rate_limit.count).to be_zero
337
337
  end
338
338
  end
339
339
  end
@@ -5,31 +5,31 @@ describe Sidekiq::Throttler::Storage::Redis do
5
5
 
6
6
  before(:each) do
7
7
  @sidekiq = double()
8
- Sidekiq.stub(:redis).and_yield(@sidekiq)
8
+ allow(Sidekiq).to receive(:redis).and_yield(@sidekiq)
9
9
  end
10
10
 
11
11
  describe "#prune" do
12
12
  it "pops the last item off the list if it's lower than the cutoff" do
13
- @sidekiq.stub(:lindex).and_return(100, nil)
14
- @sidekiq.should_receive(:rpop).with("throttled:fake").and_return(100)
13
+ allow(@sidekiq).to receive(:lindex).and_return(100, nil)
14
+ expect(@sidekiq).to receive(:rpop).with("throttled:fake").and_return(100)
15
15
  storage.prune("fake", 200)
16
16
  end
17
17
 
18
18
  it "leaves the last item on the list if it's higher than the cutoff" do
19
- @sidekiq.stub(:lindex).and_return(200, nil)
20
- @sidekiq.should_not_receive(:rpop)
19
+ allow(@sidekiq).to receive(:lindex).and_return(200, nil)
20
+ expect(@sidekiq).not_to receive(:rpop)
21
21
  storage.prune("fake", 100)
22
22
  end
23
23
 
24
24
  context "when another job has concurrently removed a timestamp" do
25
25
 
26
26
  before(:each) do
27
- @sidekiq.stub(:lindex) { 100 }
28
- @sidekiq.stub(:rpop) { 200 }
27
+ allow(@sidekiq).to receive(:lindex) { 100 }
28
+ allow(@sidekiq).to receive(:rpop) { 200 }
29
29
  end
30
30
 
31
31
  it "pushes the value back onto the list" do
32
- @sidekiq.should_receive(:rpush).with("throttled:fake", 200)
32
+ expect(@sidekiq).to receive(:rpush).with("throttled:fake", 200)
33
33
  storage.prune("fake", 1000)
34
34
  end
35
35
  end
@@ -27,7 +27,7 @@ describe Sidekiq::Throttler do
27
27
  describe '#call' do
28
28
 
29
29
  it 'instantiates a rate limit with the worker, args, and queue' do
30
- Sidekiq::Throttler::RateLimit.should_receive(:new).with(
30
+ expect(Sidekiq::Throttler::RateLimit).to receive(:new).with(
31
31
  worker, message['args'], queue, options
32
32
  ).and_call_original
33
33
 
@@ -39,15 +39,15 @@ describe Sidekiq::Throttler do
39
39
  end
40
40
 
41
41
  it 'calls RateLimit#execute' do
42
- Sidekiq::Throttler::RateLimit.any_instance.should_receive(:execute)
42
+ expect_any_instance_of(Sidekiq::Throttler::RateLimit).to receive(:execute)
43
43
  throttler.call(worker, message, queue)
44
44
  end
45
45
 
46
46
  context 'when rate limit is exceeded' do
47
47
 
48
48
  it 'requeues the job with a delay' do
49
- Sidekiq::Throttler::RateLimit.any_instance.should_receive(:exceeded?).and_return(true)
50
- worker.class.should_receive(:perform_in).with(1.minute, *message['args'])
49
+ expect_any_instance_of(Sidekiq::Throttler::RateLimit).to receive(:exceeded?).and_return(true)
50
+ expect(worker.class).to receive(:perform_in).with(1.minute, *message['args'])
51
51
  throttler.call(worker, message, queue)
52
52
  end
53
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-throttler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-24 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '2.5'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '3.1'
36
+ version: '4.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,21 +43,7 @@ dependencies:
43
43
  version: '2.5'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '3.1'
47
- - !ruby/object:Gem::Dependency
48
- name: appraisal
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.5'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.5'
46
+ version: '4.0'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: growl
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -288,7 +274,7 @@ files:
288
274
  - README.md
289
275
  - Rakefile
290
276
  - gemfiles/sidekiq_2.gemfile
291
- - gemfiles/sidekiq_head.gemfile
277
+ - gemfiles/sidekiq_master.gemfile
292
278
  - lib/sidekiq-throttler.rb
293
279
  - lib/sidekiq/throttler.rb
294
280
  - lib/sidekiq/throttler/rate_limit.rb
@@ -305,7 +291,6 @@ files:
305
291
  - spec/sidekiq/throttler/rate_limit_spec.rb
306
292
  - spec/sidekiq/throttler/storage/redis_spec.rb
307
293
  - spec/sidekiq/throttler_spec.rb
308
- - spec/spec.opts
309
294
  - spec/spec_helper.rb
310
295
  - spec/support/sidekiq.rb
311
296
  homepage: https://github.com/gevans/sidekiq-throttler
@@ -343,7 +328,6 @@ test_files:
343
328
  - spec/sidekiq/throttler/rate_limit_spec.rb
344
329
  - spec/sidekiq/throttler/storage/redis_spec.rb
345
330
  - spec/sidekiq/throttler_spec.rb
346
- - spec/spec.opts
347
331
  - spec/spec_helper.rb
348
332
  - spec/support/sidekiq.rb
349
333
  has_rdoc:
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "sidekiq", :github=>"mperham/sidekiq"
6
-
7
- gemspec :path=>"../"
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress