restrainer 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/restrainer.rb +5 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd2f59427326450c5159980282e4d463d275dac6fceaa2a31423a5433ff1502f
|
4
|
+
data.tar.gz: ddf65e8c8915e920a9689f78bce879d6feae920740890acc7c3df5f5c8ccb2d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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('
|
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.
|
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.
|
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
|
+
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.
|
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
|