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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e999370930d2d5686a75214e30aa63223b828f77ba5ba94d48506f5afcca8c9
4
- data.tar.gz: 494b772ddc967646f15f3ba1db809fd34eb6f12a0714242f327326e33af1b648
3
+ metadata.gz: b1cd37f4ccca910bb1a619d15cd176f656eae9c28832a493ae0ce14901afabaf
4
+ data.tar.gz: f55d26dfa66944e52fe1de59d791b7f8215f7afd4b0f13bb2c4cc77833c908d8
5
5
  SHA512:
6
- metadata.gz: b2b8dd65c7cd2a5d96daa8c67fe2d7b3a71a77a9035ff00a065b693d179ec1d71f6084ab1d1d8b98f5b9d62bda7628e0d898a0c32d637bc1fcb02032e3e6d7fa
7
- data.tar.gz: e4c85a817f9e0f9b2445e000b8f1f3c2cc79d74023020b8f02fa9f9895e61ee528f6b69aacc88dde8a3fbe6c04cb10f494075e7188bacf37e049486e516a2513
6
+ metadata.gz: 073671e4736562c7619f732b4fd4af031afc04617e294e4ff779f8b2c4a815c090c5ccc8bb9a7426a8c7777a86258a84c28733458b0e56c34fb2c64aa2763aec
7
+ data.tar.gz: d48174a050a831d91dc1b237aa63a584ad831936a3c310b999af7ac96f418b06c04251b98963c581a41833a95577b21b5573c7d1c5b53928e9fc432d3a169656
@@ -1,3 +1,7 @@
1
+ # 1.1.1
2
+
3
+ * Circular reference warning fix
4
+
1
5
  # 1.1.0
2
6
 
3
7
  * Expose manually locking and unlocking processes.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -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: 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
@@ -13,5 +13,7 @@ RSpec.configure do |config|
13
13
  # --seed 1234
14
14
  config.order = 'random'
15
15
 
16
- Restrainer.redis = Redis.new
16
+ redis_opts = {}
17
+ redis_opts = {url: ENV["REDIS_URL"]} if ENV["REDIS_URL"]
18
+ Restrainer.redis = Redis.new(redis_opts)
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrainer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - We Heart It