gcra 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gcra/rate_limiter.rb +25 -0
- data/lib/gcra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b29ec6abd01bba124433e5e331f1935e9ed5edc
|
4
|
+
data.tar.gz: e44c984d0d02dd54f92959e9782d4b5d755f71b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3090609da18cda2a4807eff2e2fb7faf9a354dc996c159af0e42e1412448792196ba57151204cb96085e9a05417332e387c68cddb9a68fd0527a6123d99dd5de
|
7
|
+
data.tar.gz: f18cd4c996c23bef845942364f387101d4ed452e24fe289e39ff9d5333a3059d6cedb6218eeba7050ca1ddc41f7a0db3af46d8adc0cce8bd498be8d0b984d5bd
|
data/lib/gcra/rate_limiter.rb
CHANGED
@@ -97,5 +97,30 @@ module GCRA
|
|
97
97
|
"Failed to store updated rate limit data for key '#{key}' after #{MAX_ATTEMPTS} attempts"
|
98
98
|
)
|
99
99
|
end
|
100
|
+
|
101
|
+
# Overwrite the stored value for key to that of a bucket that has
|
102
|
+
# just overflowed, ignoring any existing stored data.
|
103
|
+
def mark_overflowed(key)
|
104
|
+
key = key.to_s unless key.is_a?(String)
|
105
|
+
i = 0
|
106
|
+
while i < MAX_ATTEMPTS
|
107
|
+
tat_from_store, now = @store.get_with_time(key)
|
108
|
+
new_value = now + @delay_variation_tolerance
|
109
|
+
ttl = @delay_variation_tolerance
|
110
|
+
updated = if tat_from_store.nil?
|
111
|
+
@store.set_if_not_exists_with_ttl(key, new_value, ttl)
|
112
|
+
else
|
113
|
+
@store.compare_and_set_with_ttl(key, tat_from_store, new_value, ttl)
|
114
|
+
end
|
115
|
+
if updated
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
i += 1
|
119
|
+
end
|
120
|
+
|
121
|
+
raise StoreUpdateFailed.new(
|
122
|
+
"Failed to store updated rate limit data for key '#{key}' after #{MAX_ATTEMPTS} attempts"
|
123
|
+
)
|
124
|
+
end
|
100
125
|
end
|
101
126
|
end
|
data/lib/gcra/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Frister
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-02
|
12
|
+
date: 2019-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|