circuitry 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -11
- data/lib/circuitry/locks/base.rb +9 -1
- data/lib/circuitry/locks/memcache.rb +4 -0
- data/lib/circuitry/locks/memory.rb +6 -0
- data/lib/circuitry/locks/noop.rb +4 -0
- data/lib/circuitry/locks/redis.rb +4 -0
- data/lib/circuitry/subscriber.rb +1 -0
- data/lib/circuitry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3cb7574969d248940e91c6fbd01644acde00f1
|
4
|
+
data.tar.gz: 42d00ec555e5d84515a7715ffb9386336864ed28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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
|
-
*
|
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
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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
|
data/lib/circuitry/locks/base.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Circuitry
|
2
2
|
module Locks
|
3
3
|
module Base
|
4
|
-
DEFAULT_SOFT_TTL = (
|
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
|
data/lib/circuitry/locks/noop.rb
CHANGED
data/lib/circuitry/subscriber.rb
CHANGED
data/lib/circuitry/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-aws
|