prorate 0.7.1 → 0.7.3

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: 7e00071a8bb75be7ca3c74ecaf662e049f5c55cae7cb867c9851062efd5b8073
4
- data.tar.gz: 277671f9b2dcce7d032e9f9f38b294ced2ca953cd0f85b940d488f3ff306ee38
3
+ metadata.gz: 8756bab3df013de9ef7a962f66827fdf1e14a1c8415e226820dfb252ccc91c9a
4
+ data.tar.gz: f25dd4668ce05034652a596bfcc713bd8bb2bdeaf95b131d4c70527f9f2656f8
5
5
  SHA512:
6
- metadata.gz: 40e22d2cdb70cb407b7cc2135624a373e95e83514cfa8bb2f42a6106b40640b458a017212967fb533ba080e3e4707199a1fb1e2414b68f1289e1d24b15b05fbc
7
- data.tar.gz: 269d8ef7d384c08c928d3bed3412b2e7ae470e696ff03042744c79bd696962a9a7a82d099de8a153aef344029f40e8640d4e772bee90054b64b4f0183c96d2c9
6
+ metadata.gz: 5c49fe55ba5c947742ca46246da145b18603f4417fbfae59ea2432df4670c6a46973ae7f307e1449d432dc61106226bcd214b008beac2bc2035da8c38f06bf34
7
+ data.tar.gz: 5f65de699f025029b9923e6b93f82cb040f83b2a3d31d888e6d74763c7e50ba043f5e588ee57cc577baf7d84e3feafa282883f425d3cf97b70c3d886e91d295e
@@ -31,7 +31,8 @@ local key_lifetime = math.ceil(max_bucket_capacity / leak_rate)
31
31
 
32
32
  local blocked_until = redis.call("GET", block_key)
33
33
  if blocked_until then
34
- return {(tonumber(blocked_until) - now), 0}
34
+ -- see https://redis.io/docs/manual/programmability/lua-api/ : floats should be returned as strings or they will be cast into integers
35
+ return {(tostring(tonumber(blocked_until) - now)), -1}
35
36
  end
36
37
 
37
38
  -- get current bucket level. The throttle key might not exist yet in which
@@ -49,7 +50,7 @@ if (new_bucket_level + n_tokens) <= max_bucket_capacity then
49
50
  retval = {0, math.ceil(new_bucket_level)}
50
51
  else
51
52
  redis.call("SETEX", block_key, block_duration, now + block_duration)
52
- retval = {block_duration, 0}
53
+ retval = {tostring(block_duration), -1}
53
54
  end
54
55
 
55
56
  -- Save the new bucket level
@@ -95,9 +95,9 @@ module Prorate
95
95
  block_for: @block_for,
96
96
  n_tokens: n_tokens)
97
97
 
98
- if remaining_block_time > 0
98
+ if bucket_level == -1
99
99
  @logger.warn do
100
- "Throttle %s exceeded limit of %d in %d seconds and is blocked for the next %d seconds" % [@name, @limit, @period, remaining_block_time]
100
+ "Throttle %s exceeded limit of %d in %d seconds and is blocked for the next %s seconds" % [@name, @limit, @period, remaining_block_time]
101
101
  end
102
102
  raise ::Prorate::Throttled.new(@name, remaining_block_time)
103
103
  end
@@ -1,3 +1,3 @@
1
1
  module Prorate
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.3"
3
3
  end
data/prorate.gemspec CHANGED
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency "rspec", "~> 3.0"
35
35
  spec.add_development_dependency 'wetransfer_style', '0.6.5'
36
36
  spec.add_development_dependency 'yard', '~> 0.9'
37
- spec.add_development_dependency 'pry', '~> 0.13.1'
37
+ spec.add_development_dependency 'pry', '~> 0.14.2'
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prorate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.13.1
117
+ version: 0.14.2
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.13.1
124
+ version: 0.14.2
125
125
  description: Can be used to implement all kinds of throttles
126
126
  email:
127
127
  - me@julik.nl
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
- rubygems_version: 3.0.6
176
+ rubygems_version: 3.0.3.1
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: Time-restricted rate limiter using Redis