restrainer 1.1.0 → 1.1.1
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 +4 -4
- data/CHANGE_LOG.md +4 -0
- data/VERSION +1 -1
- data/lib/restrainer.rb +8 -8
- data/spec/spec_helper.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1cd37f4ccca910bb1a619d15cd176f656eae9c28832a493ae0ce14901afabaf
|
4
|
+
data.tar.gz: f55d26dfa66944e52fe1de59d791b7f8215f7afd4b0f13bb2c4cc77833c908d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073671e4736562c7619f732b4fd4af031afc04617e294e4ff779f8b2c4a815c090c5ccc8bb9a7426a8c7777a86258a84c28733458b0e56c34fb2c64aa2763aec
|
7
|
+
data.tar.gz: d48174a050a831d91dc1b237aa63a584ad831936a3c310b999af7ac96f418b06c04251b98963c581a41833a95577b21b5573c7d1c5b53928e9fc432d3a169656
|
data/CHANGE_LOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/restrainer.rb
CHANGED
@@ -41,7 +41,7 @@ class Restrainer
|
|
41
41
|
redis.call('zadd', sorted_set, now, process_id)
|
42
42
|
redis.call('expire', sorted_set, ttl)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
-- Return the number of processes running before the process was added.
|
46
46
|
return process_count
|
47
47
|
LUA
|
@@ -106,7 +106,7 @@ class Restrainer
|
|
106
106
|
|
107
107
|
# limit of less zero is no limit; limit of zero is allow none
|
108
108
|
return yield if limit < 0
|
109
|
-
|
109
|
+
|
110
110
|
process_id = lock!(limit: limit)
|
111
111
|
begin
|
112
112
|
yield
|
@@ -114,7 +114,7 @@ class Restrainer
|
|
114
114
|
release!(process_id)
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
# Obtain a lock on one the allowed processes. The method returns a process
|
119
119
|
# identifier that must be passed to the release! to release the lock.
|
120
120
|
# You can pass in a unique identifier if you already have one.
|
@@ -122,7 +122,7 @@ class Restrainer
|
|
122
122
|
# Raises a Restrainer::ThrottledError if the lock cannot be obtained.
|
123
123
|
#
|
124
124
|
# The limit argument can be used to override the value set in the constructor.
|
125
|
-
def lock!(process_id = nil, limit:
|
125
|
+
def lock!(process_id = nil, limit: nil)
|
126
126
|
process_id ||= SecureRandom.uuid
|
127
127
|
limit ||= self.limit
|
128
128
|
|
@@ -133,7 +133,7 @@ class Restrainer
|
|
133
133
|
add_process!(redis, process_id, limit)
|
134
134
|
process_id
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
# release one of the allowed processes. You must pass in a process id returned by the lock method.
|
138
138
|
def release!(process_id)
|
139
139
|
remove_process!(redis, process_id) unless process_id.nil?
|
@@ -143,7 +143,7 @@ class Restrainer
|
|
143
143
|
def current
|
144
144
|
redis.zcard(key).to_i
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
# Clear all locks
|
148
148
|
def clear!
|
149
149
|
redis.del(key)
|
@@ -154,7 +154,7 @@ class Restrainer
|
|
154
154
|
def redis
|
155
155
|
@redis || self.class.redis
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
# Hash key in redis to story a sorted set of current processes.
|
159
159
|
def key
|
160
160
|
@key
|
@@ -162,7 +162,7 @@ class Restrainer
|
|
162
162
|
|
163
163
|
# Add a process to the currently run set.
|
164
164
|
def add_process!(redis, process_id, throttle_limit)
|
165
|
-
process_count = eval_script(redis, process_id, throttle_limit)
|
165
|
+
process_count = eval_script(redis, process_id, throttle_limit)
|
166
166
|
if process_count >= throttle_limit
|
167
167
|
raise ThrottledError.new("#{self.class}: #{@name} already has #{process_count} processes running")
|
168
168
|
end
|
data/spec/spec_helper.rb
CHANGED