restrainer 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +1 -0
  4. data/VERSION +1 -1
  5. data/lib/restrainer.rb +5 -2
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c49c2e29f3d29970f0975f8219d99dc74a79668f263b5c923ab0eb2ff92f8fae
4
- data.tar.gz: 7af2876a48e9a34d4ff3aad0cd5fb7b12bc5e20c7ee2e875760a59276cc7c601
3
+ metadata.gz: fd2f59427326450c5159980282e4d463d275dac6fceaa2a31423a5433ff1502f
4
+ data.tar.gz: ddf65e8c8915e920a9689f78bce879d6feae920740890acc7c3df5f5c8ccb2d4
5
5
  SHA512:
6
- metadata.gz: 23d0627b6b1cca6b1c8c84ffeb20c595570c2918db27c73ce0a4a9aa158f8cf4df67cdd331d2e3b001106185c8adacffd070b215e2f47ac69b013cee1f3d11c0
7
- data.tar.gz: c7fc3e5188fa06628d7ab0f5fb4b27b74db917bb95f32ca76875c40be1052237ce83e9018c4bde079e99c09c19514dc1825a2df765f62787c910733e32e4c3f5
6
+ metadata.gz: 4166271f5f617a48286024f8e57ab7ebc662c0edfd357ced9e4e40d3998b975db1abcb4db6a1c8de2922ffc57ace7593e752798f39a6f552659877a146fff1b5
7
+ data.tar.gz: 032357eb1992399ba5d10681b7194e667d852ca000b51dcc6ac592f8d10b4734306225208c918d9c3f73faec11adf690a6d0a1ffccefab57deef09438854437a
data/CHANGELOG.md CHANGED
@@ -4,9 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.1.3
8
+
9
+ ### Added
10
+
11
+ - Support for using fractional seconds in the lock timeout.
12
+
7
13
  ## 1.1.2
8
14
 
9
15
  ### Changed
16
+
10
17
  - Redis instance will now default to a Redis instance with the default options
11
18
  instead of throwing an error if it was not set.
12
19
  - Minumum Ruby version set to 2.5
@@ -14,20 +21,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
21
  ## 1.1.1
15
22
 
16
23
  ### Fixed
24
+
17
25
  - Circular reference warning
18
26
 
19
27
  ## 1.1.0
20
28
 
21
29
  ### Added
30
+
22
31
  - Expose manually locking and unlocking processes.
23
32
  - Allow passing in a redis connection in the constructor.
24
33
 
25
34
  ## 1.0.1
26
35
 
27
36
  ### Fixed
37
+
28
38
  - Use Lua script to avoid race conditions and ensure no extra processes slip through.
29
39
 
30
40
  ## 1.0.0
31
41
 
32
42
  ### Added
43
+
33
44
  - Initial release.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![Continuous Integration](https://github.com/bdurand/restrainer/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/restrainer/actions/workflows/continuous_integration.yml)
2
2
  [![Regression Test](https://github.com/bdurand/restrainer/actions/workflows/regression_test.yml/badge.svg)](https://github.com/bdurand/restrainer/actions/workflows/regression_test.yml)
3
3
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
4
+ [![Gem Version](https://badge.fury.io/rb/restrainer.svg)](https://badge.fury.io/rb/restrainer)
4
5
 
5
6
  This gem provides a method of throttling calls across processes that can be very useful if you have to call an external service with limited resources.
6
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
data/lib/restrainer.rb CHANGED
@@ -38,7 +38,7 @@ class Restrainer
38
38
  -- Success so add to the list and set a global expiration so the list cleans up after itself.
39
39
  if process_count < limit then
40
40
  redis.call('zadd', sorted_set, now, process_id)
41
- redis.call('expire', sorted_set, ttl)
41
+ redis.call('pexpire', sorted_set, math.ceil(ttl * 1000))
42
42
  end
43
43
 
44
44
  -- Return the number of processes running before the process was added.
@@ -151,6 +151,9 @@ class Restrainer
151
151
  process_id
152
152
  end
153
153
 
154
+ def lock(process_id = nil, limit: nil)
155
+ end
156
+
154
157
  # Release one of the allowed processes. You must pass in a process id
155
158
  # returned by the lock method.
156
159
  #
@@ -209,7 +212,7 @@ class Restrainer
209
212
  end
210
213
 
211
214
  begin
212
- redis.evalsha(sha1, [], [key, process_id, throttle_limit, @timeout, Time.now.to_i])
215
+ redis.evalsha(sha1, [], [key, process_id, throttle_limit, @timeout, Time.now.to_f])
213
216
  rescue Redis::CommandError => e
214
217
  if e.message.include?("NOSCRIPT")
215
218
  sha1 = redis.script(:load, ADD_PROCESS_SCRIPT)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrainer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-11 00:00:00.000000000 Z
11
+ date: 2023-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.4.12
73
+ rubygems_version: 3.4.20
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Code for throttling workloads so as not to overwhelm external services