knifeswitch 1.0.0 → 1.1.0
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/lib/knifeswitch/circuit.rb +9 -2
- data/lib/knifeswitch/version.rb +1 -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: c21ca91eae9b7d22ebef28c43b90429e6e1c5e10501fd39e54eefffec2f2ef45
|
4
|
+
data.tar.gz: 5faa4bc86e93ad8dbff72095b2f4da97adeb8e54ebc9d0ec8191b4db0c7999ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 294756a35f27839e007c34496e550d88e95979f0252f1532536b06851de52c87f7f0fcf8f51e384976189a728a1c6d91b1f9dcb1fea918955ff022a1d16485c0
|
7
|
+
data.tar.gz: 94bc6838ab85d95ca0bc42a5ca131e487d63dbeaa67f2c5075b9d482418b08ea8a5e363b38e4b5b169d8ee080f33b827c0017754949c20de2acd0928862f13fc
|
data/lib/knifeswitch/circuit.rb
CHANGED
@@ -22,6 +22,7 @@ module Knifeswitch
|
|
22
22
|
#
|
23
23
|
class Circuit
|
24
24
|
attr_reader :namespace, :exceptions, :error_threshold, :error_timeout
|
25
|
+
attr_accessor :callback
|
25
26
|
|
26
27
|
# Options:
|
27
28
|
#
|
@@ -33,12 +34,14 @@ module Knifeswitch
|
|
33
34
|
namespace: 'default',
|
34
35
|
exceptions: [Timeout::Error],
|
35
36
|
error_threshold: 10,
|
36
|
-
error_timeout: 60
|
37
|
+
error_timeout: 60,
|
38
|
+
callback: nil
|
37
39
|
)
|
38
40
|
@namespace = namespace
|
39
41
|
@exceptions = exceptions
|
40
42
|
@error_threshold = error_threshold
|
41
43
|
@error_timeout = error_timeout
|
44
|
+
@callback = callback
|
42
45
|
end
|
43
46
|
|
44
47
|
# Call this with a block to execute the contents of the block under
|
@@ -46,7 +49,10 @@ module Knifeswitch
|
|
46
49
|
#
|
47
50
|
# Raises Knifeswitch::CircuitOpen when called while the circuit is open.
|
48
51
|
def run
|
49
|
-
|
52
|
+
if open?
|
53
|
+
callback.try(:call, CircuitOpen.new)
|
54
|
+
raise CircuitOpen
|
55
|
+
end
|
50
56
|
|
51
57
|
result = yield
|
52
58
|
reset_counter!
|
@@ -54,6 +60,7 @@ module Knifeswitch
|
|
54
60
|
rescue Exception => error
|
55
61
|
if exceptions.any? { |watched| error.is_a?(watched) }
|
56
62
|
increment_counter!
|
63
|
+
callback.try(:call, error)
|
57
64
|
else
|
58
65
|
reset_counter!
|
59
66
|
end
|
data/lib/knifeswitch/version.rb
CHANGED