rapidity 0.0.1 → 0.0.2.59005
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -3
- data/LICENSE +19 -0
- data/lib/rapidity.rb +1 -1
- data/lib/rapidity/composer.rb +11 -11
- data/lib/rapidity/limiter.rb +6 -8
- data/lib/rapidity/version.rb +5 -2
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 004e68dd80ed2ad9d0956207e413d092320406ef7d889956de8e93d9bf9b7327
|
4
|
+
data.tar.gz: c2c05a95c87bb97655d0d0cf827a6db4294933315e2dc518c7fb398a4b82725d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2eceaa1080720fdd72a47498dc7843f1387124d5519757eacf2217c6b85cf6384b7853cb904d33437de83bc2bad4d6a9b3db923331876687868157672913a6a
|
7
|
+
data.tar.gz: 5d581e6817bb736228e333fcb6586c882a2ea9b8e98a0d3b3911b2dca08985d922fb1fc0e5f8f46e35a01a84cd9a2400def848482c5c2d8d5f21c1abeb922e3d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rapidity (0.0.
|
4
|
+
rapidity (0.0.2.59005)
|
5
5
|
activesupport
|
6
6
|
connection_pool
|
7
7
|
redis
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
psych (3.3.2)
|
59
59
|
public_suffix (4.0.6)
|
60
60
|
rainbow (3.0.0)
|
61
|
-
redis (4.
|
61
|
+
redis (4.4.0)
|
62
62
|
reek (6.0.4)
|
63
63
|
kwalify (~> 0.7.0)
|
64
64
|
parser (~> 3.0.0)
|
@@ -123,6 +123,7 @@ GEM
|
|
123
123
|
zeitwerk (2.4.2)
|
124
124
|
|
125
125
|
PLATFORMS
|
126
|
+
ruby
|
126
127
|
x86_64-linux
|
127
128
|
|
128
129
|
DEPENDENCIES
|
@@ -141,4 +142,4 @@ DEPENDENCIES
|
|
141
142
|
timeouter
|
142
143
|
|
143
144
|
BUNDLED WITH
|
144
|
-
2.2.
|
145
|
+
2.2.14
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014-2021 Рнд Софт
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/lib/rapidity.rb
CHANGED
data/lib/rapidity/composer.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'ostruct'
|
3
2
|
|
4
3
|
require_relative './limiter'
|
@@ -9,30 +8,30 @@ module Rapidity
|
|
9
8
|
|
10
9
|
attr_reader :limits, :limiters, :name, :namespace
|
11
10
|
|
12
|
-
# Combine multiple limits
|
11
|
+
# Combine multiple limits
|
13
12
|
# @params pool - inititalized Redis pool
|
14
13
|
# @params name - limiter name - part of the Redis key name
|
15
14
|
# @params limits - multiple limits definition
|
16
15
|
|
17
16
|
## limits example
|
18
17
|
# ```ruby`
|
19
|
-
#limits = [
|
18
|
+
# limits = [
|
20
19
|
# { threshold: 2, interval: 1 }, # 2 events per second
|
21
20
|
# { threshold: 9, interval: 5 }, # 9 events per 5 seconds
|
22
21
|
# { threshold: 20, interval: 20 }, # 20 events per 20 seconds
|
23
22
|
# { threshold: 42, interval: 60 }, # 42 events per 60 seconds
|
24
|
-
#]
|
25
|
-
|
26
|
-
|
23
|
+
# ]
|
24
|
+
# ```
|
27
25
|
# @params namespace - namespace for Redis keys
|
28
|
-
def initialize
|
26
|
+
def initialize(pool, name:, limits: [], namespace: 'rapidity')
|
29
27
|
@limits = limits
|
30
28
|
@name = name
|
31
29
|
@namespace = namespace
|
32
|
-
|
30
|
+
|
33
31
|
@limiters = @limits.map.each_with_index do |l, i|
|
34
32
|
limit = OpenStruct.new(l)
|
35
|
-
::Rapidity::Limiter.new(pool, name: "#{i}_#{name}_#{limit.
|
33
|
+
::Rapidity::Limiter.new(pool, name: "#{i}_#{name}_#{limit.threshold}/#{limit.interval}",
|
34
|
+
interval: limit.interval, threshold: limit.threshold, namespace: namespace)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -48,8 +47,9 @@ module Rapidity
|
|
48
47
|
break if count == 0
|
49
48
|
end
|
50
49
|
|
51
|
-
|
50
|
+
count
|
52
51
|
end
|
53
52
|
|
54
53
|
end
|
55
|
-
end
|
54
|
+
end
|
55
|
+
|
data/lib/rapidity/limiter.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'connection_pool'
|
3
2
|
require 'redis'
|
4
3
|
|
@@ -14,12 +13,12 @@ module Rapidity
|
|
14
13
|
# @params interval - interval in seconds to apply this limit
|
15
14
|
# @params threshold - maximum available events for this interval
|
16
15
|
# @params namespace - namespace for Redis keys
|
17
|
-
def initialize
|
16
|
+
def initialize(pool, name:, interval: 10, threshold: 10, namespace: 'rapidity')
|
18
17
|
@pool = pool
|
19
18
|
@interval = interval
|
20
19
|
@threshold = threshold
|
21
20
|
@name = name
|
22
|
-
|
21
|
+
|
23
22
|
@namespace = namespace
|
24
23
|
end
|
25
24
|
|
@@ -49,7 +48,7 @@ module Rapidity
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
|
51
|
+
if taken < 0
|
53
52
|
overflow = taken.abs
|
54
53
|
to_return = [count, overflow].min
|
55
54
|
|
@@ -60,13 +59,12 @@ module Rapidity
|
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
|
-
count -
|
62
|
+
count - to_return
|
64
63
|
else
|
65
64
|
count
|
66
65
|
end
|
67
|
-
|
68
|
-
return obtained
|
69
66
|
end
|
70
67
|
|
71
68
|
end
|
72
|
-
end
|
69
|
+
end
|
70
|
+
|
data/lib/rapidity/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapidity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.59005
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yurusov Vlad
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-08-
|
12
|
+
date: 2021-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: connection_pool
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: redis
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
@@ -54,47 +54,47 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
62
|
+
version: '2.0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
69
|
+
version: '2.0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '3.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '3.0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: timeouter
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '
|
90
|
+
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
97
|
+
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: awesome_print
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -231,6 +231,7 @@ extra_rdoc_files: []
|
|
231
231
|
files:
|
232
232
|
- Gemfile
|
233
233
|
- Gemfile.lock
|
234
|
+
- LICENSE
|
234
235
|
- lib/rapidity.rb
|
235
236
|
- lib/rapidity/composer.rb
|
236
237
|
- lib/rapidity/limiter.rb
|
@@ -246,14 +247,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
246
247
|
requirements:
|
247
248
|
- - ">="
|
248
249
|
- !ruby/object:Gem::Version
|
249
|
-
version:
|
250
|
+
version: 2.5.0
|
250
251
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
251
252
|
requirements:
|
252
253
|
- - ">="
|
253
254
|
- !ruby/object:Gem::Version
|
254
255
|
version: '0'
|
255
256
|
requirements: []
|
256
|
-
rubygems_version: 3.
|
257
|
+
rubygems_version: 3.0.3
|
257
258
|
signing_key:
|
258
259
|
specification_version: 4
|
259
260
|
summary: Simple distributed Redis-backed rate limiter
|