circuitry 1.2.0 → 1.2.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
  SHA1:
3
- metadata.gz: aabb7e5d67924cf49e3d6efdd5f34c27d4d850f6
4
- data.tar.gz: b63bad1d70be23cec5c666b699f8473b25a2d7cb
3
+ metadata.gz: 7d3cb7574969d248940e91c6fbd01644acde00f1
4
+ data.tar.gz: 42d00ec555e5d84515a7715ffb9386336864ed28
5
5
  SHA512:
6
- metadata.gz: 01e354ad6cfaccaf54184d932714609fbad3e95c9f0a35137e756abe5448fc4fda5b7a8f52333d7dc7f05e4b80d4d2cb2c3a30b52e271e90cc70ddd2e6efd4ab
7
- data.tar.gz: 146e463dc1f63ea887ec99ffbd350d9b28d9f3aff2d96fca12ce407c200a2f3a1480ce2b4be15747980f533ec00e2716854607ec53e46249b6a705e74d137bcf
6
+ metadata.gz: d14efee260aefebf4b7c0448d67ac318d5b7d3970f4af9e7724342208d054d134ccb315bb9c112d971c7aee8b8df0378e1df715d33e74c6d98c8edc1bea39d38
7
+ data.tar.gz: 592e95bbf220f32c9cc5ac0891347b513d8b4f5dee94b17395fe3a07fcba03b2f04a02ff478864944681e894cf0d197a0f283032d7941e3f6808de7b98b8beef
data/README.md CHANGED
@@ -36,7 +36,7 @@ Circuitry.config do |c|
36
36
  HoneyBadger.notify(error)
37
37
  HoneyBadger.flush
38
38
  end
39
- c.lock_strategy = Circuitry::Lock::Redis.new(url: 'redis://localhost:6379')
39
+ c.lock_strategy = Circuitry::Locks::Redis.new(url: 'redis://localhost:6379')
40
40
  c.publish_async_strategy = :batch
41
41
  c.subscribe_async_strategy = :thread
42
42
  end
@@ -55,7 +55,7 @@ Available configuration options include:
55
55
  * `error_handler`: An object that responds to `call` with two arguments: the
56
56
  deserialized message contents and the topic name used when publishing to SNS.
57
57
  *(optional, default: `nil`)*
58
- * `:lock_strategy` - The store used to ensure that no duplicate messages are
58
+ * `lock_strategy` - The store used to ensure that no duplicate messages are
59
59
  processed. Please refer to the [Lock Strategies](#lock-strategies) section for
60
60
  more details regarding this option. *(default: `Circuitry::Locks::Memory.new`)*
61
61
  * `publish_async_strategy`: One of `:fork`, `:thread`, or `:batch` that
@@ -247,7 +247,7 @@ The circuitry gem handles this by caching SQS message IDs: first via a "soft
247
247
  lock" that denotes the message is about to be processed, then via a "hard lock"
248
248
  that denotes the message has finished processing.
249
249
 
250
- The soft lock has a default TTL of 15 minutes (a seemingly sane amount of time
250
+ The soft lock has a default TTL of 5 minutes (a seemingly sane amount of time
251
251
  during which processing most queue messages should certainly be able to
252
252
  complete), while the hard lock has a default TTL of 24 hours (based upon
253
253
  [a suggestion by an AWS employee](https://forums.aws.amazon.com/thread.jspa?threadID=140782#507605)).
@@ -256,7 +256,7 @@ The soft and hard TTL values can be changed by passing a `:soft_ttl` or
256
256
  that a lock should persist. For example:
257
257
 
258
258
  ```ruby
259
- Circuitry.config.lock_strategy = Circuitry::Lock::Memory.new(
259
+ Circuitry.config.lock_strategy = Circuitry::Locks::Memory.new(
260
260
  soft_ttl: 10 * 60, # 10 minutes
261
261
  hard_ttl: 48 * 60 * 60 # 48 hours
262
262
  )
@@ -271,7 +271,7 @@ multiple subscriber processes or if expecting a high throughput that would resul
271
271
  in a large amount of memory consumption.
272
272
 
273
273
  ```ruby
274
- Circuitry::Lock::Memory.new
274
+ Circuitry::Locks::Memory.new
275
275
  ```
276
276
 
277
277
  #### Redis
@@ -284,7 +284,7 @@ redis connection options to the lock in the same way that you would when buildin
284
284
  a new `Redis` object.
285
285
 
286
286
  ```ruby
287
- Circuitry::Lock::Redis.new(url: 'redis://localhost:6379')
287
+ Circuitry::Locks::Redis.new(url: 'redis://localhost:6379')
288
288
  ```
289
289
 
290
290
  The second way is to pass in a `:client` option that specifies the redis client
@@ -294,7 +294,7 @@ or utilizing [hiredis](https://github.com/redis/hiredis-rb).
294
294
 
295
295
  ```ruby
296
296
  client = Redis.new(url: 'redis://localhost:6379')
297
- Circuitry::Lock::Redis.new(client: client)
297
+ Circuitry::Locks::Redis.new(client: client)
298
298
  ```
299
299
 
300
300
  #### Memcache
@@ -308,7 +308,7 @@ building a new `Dalli::Client` object. The special `host` option will be treate
308
308
  as the memcache host, just as the first argument to `Dalli::Client`.
309
309
 
310
310
  ```ruby
311
- Circuitry::Lock::Memcache.new(host: 'localhost:11211', namespace: '...')
311
+ Circuitry::Locks::Memcache.new(host: 'localhost:11211', namespace: '...')
312
312
  ```
313
313
 
314
314
  The second way is to pass in a `:client` option that specifies the dalli client
@@ -316,7 +316,7 @@ itself. This is useful for sharing an existing memcache connection.
316
316
 
317
317
  ```ruby
318
318
  client = Dalli::Client.new('localhost:11211', namespace: '...')
319
- Circuitry::Lock::Memcache.new(client: client)
319
+ Circuitry::Locks::Memcache.new(client: client)
320
320
  ```
321
321
 
322
322
  #### NOOP
@@ -329,7 +329,7 @@ messages. Please refer to the Amazon SQS documentation pertaining to the
329
329
  #### Custom
330
330
 
331
331
  It's also possible to roll your own lock strategy. Simply create a class that
332
- includes (or module that extends) `Circuitry::Lock::Base` and implements the
332
+ includes (or module that extends) `Circuitry::Locks::Base` and implements the
333
333
  following methods:
334
334
 
335
335
  * `lock`: Accepts the `key` and `ttl` as parameters. If the key is already
@@ -339,12 +339,14 @@ following methods:
339
339
  processed more than once.
340
340
  * `lock!`: Accepts the `key` and `ttl` as parameters. Must lock the key for
341
341
  `ttl` seconds regardless of whether or not the key was previously locked.
342
+ * `unlock!`: Accepts the `key` as a parameter. Must unlock (delete) the key if
343
+ it was previously locked.
342
344
 
343
345
  For example, a database-backed solution might look something like the following:
344
346
 
345
347
  ```ruby
346
348
  class DatabaseLockStrategy
347
- include Circuitry::Lock::Base
349
+ include Circuitry::Locks::Base
348
350
 
349
351
  def initialize(options = {})
350
352
  super(options)
@@ -361,6 +363,10 @@ class DatabaseLockStrategy
361
363
  connection.exec("UPSERT INTO locks (key, expires_at) VALUES ('#{key}', '#{Time.now + ttl}')")
362
364
  end
363
365
 
366
+ def unlock!(key)
367
+ connection.exec("DELETE FROM locks WHERE key = '#{key}'")
368
+ end
369
+
364
370
  private
365
371
 
366
372
  attr_reader :connection
@@ -1,7 +1,7 @@
1
1
  module Circuitry
2
2
  module Locks
3
3
  module Base
4
- DEFAULT_SOFT_TTL = (15 * 60).freeze # 15 minutes
4
+ DEFAULT_SOFT_TTL = (5 * 60).freeze # 5 minutes
5
5
  DEFAULT_HARD_TTL = (24 * 60 * 60).freeze # 24 hours
6
6
 
7
7
  attr_reader :soft_ttl, :hard_ttl
@@ -19,6 +19,10 @@ module Circuitry
19
19
  lock!(lock_key(id), hard_ttl)
20
20
  end
21
21
 
22
+ def unlock(id)
23
+ unlock!(lock_key(id))
24
+ end
25
+
22
26
  protected
23
27
 
24
28
  def lock(key, ttl)
@@ -29,6 +33,10 @@ module Circuitry
29
33
  raise NotImplementedError
30
34
  end
31
35
 
36
+ def unlock!(key)
37
+ raise NotImplementedError
38
+ end
39
+
32
40
  private
33
41
 
34
42
  attr_writer :soft_ttl, :hard_ttl
@@ -22,6 +22,10 @@ module Circuitry
22
22
  client.set(key, (Time.now + ttl).to_i, ttl)
23
23
  end
24
24
 
25
+ def unlock!(key)
26
+ client.delete(key)
27
+ end
28
+
25
29
  private
26
30
 
27
31
  attr_accessor :client
@@ -36,6 +36,12 @@ module Circuitry
36
36
  end
37
37
  end
38
38
 
39
+ def unlock!(key)
40
+ store do |store|
41
+ store.delete(key)
42
+ end
43
+ end
44
+
39
45
  private
40
46
 
41
47
  def store(&block)
@@ -12,6 +12,10 @@ module Circuitry
12
12
  def lock!(key, ttl)
13
13
  # do nothing
14
14
  end
15
+
16
+ def unlock!(key)
17
+ # do nothing
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -22,6 +22,10 @@ module Circuitry
22
22
  client.set(key, (Time.now + ttl).to_i, ex: ttl)
23
23
  end
24
24
 
25
+ def unlock!(key)
26
+ client.del(key)
27
+ end
28
+
25
29
  private
26
30
 
27
31
  attr_accessor :client
@@ -116,6 +116,7 @@ module Circuitry
116
116
  block.call(message.body, message.topic.name)
117
117
  end
118
118
  rescue => e
119
+ lock.unlock(message.id)
119
120
  logger.error("Error handling message #{message.id}: #{e}")
120
121
  raise e
121
122
  end
@@ -1,3 +1,3 @@
1
1
  module Circuitry
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuitry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Huggins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-aws