circuit_breakage 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -4
- data/lib/circuit_breakage.rb +2 -4
- data/lib/circuit_breakage/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b436b7a83a4e4470cf5bf209e276afa440eea28d
|
4
|
+
data.tar.gz: bbf480897ba2a7db87096a939b505617bdaccb17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dacf62b792eadf2d5c9589eb221a028f5e597a071362374357e200c5c0a41b33313243e99851fd9daa8d654aab52228d754350354d04e68afaaddf821e84de48
|
7
|
+
data.tar.gz: 77455e880e39b757d046a11fb1e6cfe1394a88a947601a5b8adbbf8c55883b3dd5000b236485cdc5e696b7d971e507cff1a81b04e7935f7551e4b9f7e46121f6
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# CircuitBreakage
|
2
2
|
|
3
3
|
A simple Circuit Breaker implementation in Ruby with a timeout. A Circuit
|
4
|
-
Breaker wraps potentially troublesome
|
5
|
-
stop trying to run the
|
6
|
-
will retry.
|
4
|
+
Breaker wraps a potentially troublesome block of code and will "trip" the
|
5
|
+
circuit (ie, stop trying to run the code) if it sees too many failures. After
|
6
|
+
a configurable amount of time, the circuit breaker will retry.
|
7
|
+
|
8
|
+
See http://martinfowler.com/bliki/CircuitBreaker.html for a more complete
|
9
|
+
description of the pattern.
|
7
10
|
|
8
11
|
## Usage
|
9
12
|
|
@@ -28,6 +31,9 @@ rescue CircuitBreaker::CircuitTimeout
|
|
28
31
|
end
|
29
32
|
```
|
30
33
|
|
34
|
+
A "failure" in this context means that the block either raised an exception or
|
35
|
+
timed out.
|
36
|
+
|
31
37
|
### Redis-backed "Shared" Circuit Breakers
|
32
38
|
|
33
39
|
The unique feature of this particular Circuit Breaker gem is that it also
|
@@ -42,8 +48,19 @@ the retry timer as appropriate.
|
|
42
48
|
|
43
49
|
```ruby
|
44
50
|
connection = some_redis_connection
|
45
|
-
key = 'my_app/
|
51
|
+
key = 'my_app/this_operation'
|
46
52
|
|
47
53
|
breaker = CircuitBreakage::RedisBackedBreaker.new(connection, key, block)
|
54
|
+
breaker.lock_timeout = 30 # seconds before assuming a locking process has crashed
|
55
|
+
|
48
56
|
# Everything else is the same as above.
|
49
57
|
```
|
58
|
+
|
59
|
+
The `lock_timeout` setting is necessary since a process that crashes or is
|
60
|
+
killed might be holding the retry lock. This sets the amount of time other
|
61
|
+
processes will wait before deciding a lock has expired. It should be longer
|
62
|
+
than the amount of time you expect the block to take to run.
|
63
|
+
|
64
|
+
All circuit breakers using the same key and the same Redis instance will share
|
65
|
+
their state . It is strongly recommended that their settings
|
66
|
+
(failure_threshold, duration, etc) all be configured the same!
|
data/lib/circuit_breakage.rb
CHANGED