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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3452315467fe2c079071179703283dd9ea92eb8e6abcc959905f40e16f3e2414
4
- data.tar.gz: 90d783190f15f57c3ac44dc2afc89fb5a000a392163ab9a8351ff498e323901a
3
+ metadata.gz: 04cc88a51db5eca83f7843c1d34cf86213a0ca412fd404e3fff88b3b6994ea8d
4
+ data.tar.gz: 4eb67771a03cd0f4179d8d80655efcad738cb877b2fb5813399f136dc743090c
5
5
  SHA512:
6
- metadata.gz: 228f67adfb24027a6ea3c7b090c64aecee1a38e64ed00f7272b0c1af273dbcc73bbec8112fbb15595133cd450b45ac10f603e30ad252218d41e66d5206cc549d
7
- data.tar.gz: 9068fd600128bb11f718318fa41f1030d17cd5ad36b9ce5884cbdc5f105fe56f92da73568dc60f12f6e1c7a64402652381259a64524c80889465d4c794a91e69
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 = BaseLimiter::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)
@@ -1,8 +1,6 @@
1
1
  module Berater
2
2
  class BaseLimiter
3
3
 
4
- class Overloaded < StandardError; end
5
-
6
4
  attr_reader :options
7
5
 
8
6
  def initialize(**opts)
@@ -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 ttl = tonumber(ARGV[2])
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(LUA_SCRIPT, [ key ], [ capacity, timeout ])
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
 
@@ -1,3 +1,3 @@
1
1
  module Berater
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-04 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis