prop 0.3.6 → 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.
- data/README.rdoc +9 -0
- data/VERSION +1 -1
- data/lib/prop.rb +2 -2
- data/prop.gemspec +13 -15
- data/test/helper.rb +1 -0
- data/test/test_prop.rb +12 -1
- metadata +7 -8
- data/.gitignore +0 -21
data/README.rdoc
CHANGED
@@ -54,6 +54,15 @@ If you wish to reset a specific throttle, you can do that like so:
|
|
54
54
|
|
55
55
|
When the threshold are invoked without argument, the key is nil and as such a scope of its own.
|
56
56
|
|
57
|
+
The default (and smallest possible) increment is 1, you can of course set that to any integer value using :increment
|
58
|
+
|
59
|
+
Prop.setup(:execution_time_ms, :threshold => 1000, :interval => 1.minute)
|
60
|
+
Prop.throttle_execution_time_ms!(:increment => (Benchmark.realtime { execute } * 1000).to_i)
|
61
|
+
|
62
|
+
You can gauge the current value of a throttle using count:
|
63
|
+
|
64
|
+
Prop.count_mails_per_hour!(mail.from)
|
65
|
+
|
57
66
|
Lastly you can use Prop without registering the thresholds up front:
|
58
67
|
|
59
68
|
Prop.throttle!(:key => 'nuisance@example.com', :threshold => 100, :interval -> 1.hour)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.1
|
data/lib/prop.rb
CHANGED
@@ -65,7 +65,7 @@ class Prop
|
|
65
65
|
end
|
66
66
|
raise Prop::RateLimitExceededError.create(options[:key], options[:threshold], options[:message])
|
67
67
|
else
|
68
|
-
writer.call(sanitized_prop_key(options), counter + 1)
|
68
|
+
writer.call(sanitized_prop_key(options), counter + [ 1, options[:increment].to_i ].max)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -93,7 +93,7 @@ class Prop
|
|
93
93
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
94
94
|
return {
|
95
95
|
:key => normalize_cache_key(args), :message => defaults[:message], :progressive => defaults[:progressive],
|
96
|
-
:threshold => defaults[:threshold].to_i, :interval => defaults[:interval].to_i
|
96
|
+
:threshold => defaults[:threshold].to_i, :interval => defaults[:interval].to_i, :increment => defaults[:increment]
|
97
97
|
}.merge(options)
|
98
98
|
end
|
99
99
|
|
data/prop.gemspec
CHANGED
@@ -1,41 +1,39 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{prop}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Morten Primdahl"]
|
12
|
-
s.date = %q{2010-08
|
12
|
+
s.date = %q{2010-12-08}
|
13
13
|
s.description = %q{A gem for implementing rate limiting}
|
14
14
|
s.email = %q{morten@zendesk.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"test/test_prop.rb"
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/prop.rb",
|
26
|
+
"prop.gemspec",
|
27
|
+
"test/helper.rb",
|
28
|
+
"test/test_prop.rb"
|
30
29
|
]
|
31
30
|
s.homepage = %q{http://github.com/morten/prop}
|
32
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
33
31
|
s.require_paths = ["lib"]
|
34
32
|
s.rubygems_version = %q{1.3.7}
|
35
33
|
s.summary = %q{Puts a cork in their requests}
|
36
34
|
s.test_files = [
|
37
35
|
"test/helper.rb",
|
38
|
-
|
36
|
+
"test/test_prop.rb"
|
39
37
|
]
|
40
38
|
|
41
39
|
if s.respond_to? :specification_version then
|
data/test/helper.rb
CHANGED
data/test/test_prop.rb
CHANGED
@@ -140,7 +140,7 @@ class TestProp < Test::Unit::TestCase
|
|
140
140
|
assert_raises(Prop::RateLimitExceededError) { Prop.throttle_progressive! }
|
141
141
|
end
|
142
142
|
|
143
|
-
should "not increment the counter
|
143
|
+
should "not increment the counter beyond the threshold" do
|
144
144
|
10.times do |i|
|
145
145
|
Prop.throttle!(:key => 'hello', :threshold => 5, :interval => 10) rescue nil
|
146
146
|
end
|
@@ -148,6 +148,17 @@ class TestProp < Test::Unit::TestCase
|
|
148
148
|
assert_equal 5, Prop.count(:key => 'hello', :threshold => 5, :interval => 10)
|
149
149
|
end
|
150
150
|
|
151
|
+
should "support custom increments" do
|
152
|
+
Prop.throttle!(:key => 'hello', :threshold => 100, :interval => 10)
|
153
|
+
Prop.throttle!(:key => 'hello', :threshold => 100, :interval => 10)
|
154
|
+
|
155
|
+
assert_equal 2, Prop.count(:key => 'hello', :threshold => 100, :interval => 10)
|
156
|
+
|
157
|
+
Prop.throttle!(:key => 'hello', :threshold => 100, :interval => 10, :increment => 48)
|
158
|
+
|
159
|
+
assert_equal 50, Prop.count(:key => 'hello', :threshold => 100, :interval => 10)
|
160
|
+
end
|
161
|
+
|
151
162
|
should "raise Prop::RateLimitExceededError when the threshold is exceeded" do
|
152
163
|
5.times do |i|
|
153
164
|
Prop.throttle!(:key => 'hello', :threshold => 5, :interval => 10)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08
|
18
|
+
date: 2010-12-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -59,7 +59,6 @@ extra_rdoc_files:
|
|
59
59
|
- README.rdoc
|
60
60
|
files:
|
61
61
|
- .document
|
62
|
-
- .gitignore
|
63
62
|
- LICENSE
|
64
63
|
- README.rdoc
|
65
64
|
- Rakefile
|
@@ -73,8 +72,8 @@ homepage: http://github.com/morten/prop
|
|
73
72
|
licenses: []
|
74
73
|
|
75
74
|
post_install_message:
|
76
|
-
rdoc_options:
|
77
|
-
|
75
|
+
rdoc_options: []
|
76
|
+
|
78
77
|
require_paths:
|
79
78
|
- lib
|
80
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|