excess_flow 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb4d99f396cab3a0284b7d82ec64fbd70c2dff2c43f6eac8420291a522641572
4
- data.tar.gz: ac6d5775cd62ae23e4b972533dc2837e37ca96cfa02c4e85920a157d4c8b5e5e
3
+ metadata.gz: ba273741f4b6cb0d38335b7ee7eba8c9283604ce30e2e4463c3dca614ec67f2c
4
+ data.tar.gz: 44a3a1ef66b0163008e8a62a1c250ac565d7e59e155eab3e18b1f1b4014c8e0b
5
5
  SHA512:
6
- metadata.gz: ae13311decf56aa76a60e043a39b378cc57189bb58a4999982199607a4e76e0f77d97d384c645cef00b0f91d6a6a2d074af1fdc307cbf7cfaff021f8181ce9c0
7
- data.tar.gz: f1822c55125151241c0521e65a46699afaba66e71e2971371ebdab9064422706aff97168e984666665b80384dc452bb6f114475b88c42d0bb4695de00a5d3e06
6
+ metadata.gz: 4aacbfcf9b81aeb05024920ab3cbd5e1e2aeb70ce60c65b5cbc7fbea918415609f4dd16067955d1e0d7939f3fec39fa2ef2455709b63baf8dc63a205800c9d6f
7
+ data.tar.gz: 9d357b9e4622e08dc348c478b6980ddb2d238e4ef6e69b2900996361e35d1f0ac3d189bb40c92f6ee5db62577e4d055f679d4fb91a63bd688f0c2c2dc91ca815
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.4
4
+ - When setting expiration window rely on TTL and not counts
5
+ [#3](https://github.com/ConvertKit/excess_flow/pull/3)
6
+
3
7
  ## 1.0.3
4
8
  - Bumping up gems in Gemfile.lock
5
9
  - Adding test to test window expiration for `FixedWindowStrategy`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- excess_flow (1.0.3)
4
+ excess_flow (1.0.4)
5
5
  connection_pool
6
6
  rake
7
7
  redis
@@ -23,5 +23,5 @@ module ExcessFlow
23
23
  LOCK_PREFIX = 'excess_flow::lock::'
24
24
  MUTEX_LOCK_TIME = 1
25
25
  MUTEX_SLEEP_TIME = 1 / 100_000
26
- VERSION = '1.0.3'
26
+ VERSION = '1.0.4'
27
27
  end
@@ -46,8 +46,12 @@ module ExcessFlow
46
46
  @current_requests ||= ExcessFlow.redis { |r| r.get(configuration.counter_key) }.to_i
47
47
  end
48
48
 
49
+ def current_ttl
50
+ @current_ttl ||= ExcessFlow.redis { |r| r.ttl(configuration.counter_key) }.to_i
51
+ end
52
+
49
53
  def start_expiration_window
50
- return unless current_requests.zero?
54
+ return unless current_ttl.negative?
51
55
 
52
56
  ExcessFlow.redis { |r| r.expire(configuration.counter_key, configuration.ttl) }
53
57
  end
@@ -60,12 +60,16 @@ module ExcessFlow
60
60
  @current_requests ||= ExcessFlow.redis { |r| r.zcount(configuration.counter_key, '-inf', '+inf') }
61
61
  end
62
62
 
63
+ def current_ttl
64
+ @current_ttl ||= ExcessFlow.redis { |r| r.ttl(configuration.counter_key) }.to_i
65
+ end
66
+
63
67
  def current_timestamp
64
68
  @current_timestamp ||= (Time.now.to_f * 100_000).to_i
65
69
  end
66
70
 
67
71
  def start_expiration_window
68
- return if current_requests.zero?
72
+ return if current_ttl.negative?
69
73
 
70
74
  ExcessFlow.redis { |r| r.expire(configuration.counter_key, configuration.ttl) }
71
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excess_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ConvertKit, LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool