berater 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/berater.rb +8 -6
- data/lib/berater/base_limiter.rb +0 -2
- data/lib/berater/concurrency_limiter.rb +7 -2
- data/lib/berater/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04cc88a51db5eca83f7843c1d34cf86213a0ca412fd404e3fff88b3b6994ea8d
|
4
|
+
data.tar.gz: 4eb67771a03cd0f4179d8d80655efcad738cb877b2fb5813399f136dc743090c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9715ae524f7b0fdbbd60d352546ac86a0984f4a5e8966351ae00057e976c391076c270677b29f83c813043c24ad6fa7cae571f224df6400e98fa43bdb4f06cb6
|
7
|
+
data.tar.gz: 16999ff18ea843d12ce6b847b79ddf3bc2b4372cf01371a63d36213ccc27717e06e8794f6b4a519a59af7cba1afaed3cc3ca92a5baed60302e6f1fe114dd29ac
|
data/lib/berater.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
require 'berater/base_limiter'
|
2
|
-
require 'berater/concurrency_limiter'
|
3
|
-
require 'berater/inhibitor'
|
4
|
-
require 'berater/rate_limiter'
|
5
|
-
require 'berater/unlimiter'
|
6
1
|
require 'berater/version'
|
7
2
|
|
8
3
|
|
9
4
|
module Berater
|
10
5
|
extend self
|
11
6
|
|
12
|
-
Overloaded
|
7
|
+
class Overloaded < StandardError; end
|
13
8
|
|
14
9
|
MODES = {}
|
15
10
|
|
@@ -56,6 +51,13 @@ module Berater
|
|
56
51
|
|
57
52
|
end
|
58
53
|
|
54
|
+
# load and register limiters
|
55
|
+
require 'berater/base_limiter'
|
56
|
+
require 'berater/concurrency_limiter'
|
57
|
+
require 'berater/inhibitor'
|
58
|
+
require 'berater/rate_limiter'
|
59
|
+
require 'berater/unlimiter'
|
60
|
+
|
59
61
|
Berater.register(:concurrency, Berater::ConcurrencyLimiter)
|
60
62
|
Berater.register(:inhibited, Berater::Inhibitor)
|
61
63
|
Berater.register(:rate, Berater::RateLimiter)
|
data/lib/berater/base_limiter.rb
CHANGED
@@ -62,7 +62,8 @@ module Berater
|
|
62
62
|
LUA_SCRIPT = <<~LUA.gsub(/^\s*(--.*\n)?/, '')
|
63
63
|
local key = KEYS[1]
|
64
64
|
local capacity = tonumber(ARGV[1])
|
65
|
-
local
|
65
|
+
local ts = tonumber(ARGV[2])
|
66
|
+
local ttl = tonumber(ARGV[3])
|
66
67
|
|
67
68
|
local exists
|
68
69
|
local count
|
@@ -124,7 +125,11 @@ module Berater
|
|
124
125
|
).limit(&block)
|
125
126
|
end
|
126
127
|
|
127
|
-
count, lock_id = redis.eval(
|
128
|
+
count, lock_id = redis.eval(
|
129
|
+
LUA_SCRIPT,
|
130
|
+
[ key ],
|
131
|
+
[ capacity, Time.now.to_i, timeout ]
|
132
|
+
)
|
128
133
|
|
129
134
|
raise Incapacitated unless lock_id
|
130
135
|
|
data/lib/berater/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|