breaker_machines 0.18.0 → 0.19.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/breaker_machines/circuit/native.rb +14 -16
- data/lib/breaker_machines/storage/memory.rb +5 -3
- data/lib/breaker_machines/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: 6172f37c8307d66dbacea1526038a00deb457e16ea404ea877cd4d4c8f5c18bd
|
|
4
|
+
data.tar.gz: e246c2d0d5a4df91003105a4ccb2ee5d00593bda8a4d339f8eeb5fd28ac16d41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4145bd486e2645b57eab3058671ba08143ac1422a11a68ba00b3079d3c35981d6c8b8c470e2f0de75af59c2799d780a360f74739e43b1022bfd447de6bc5dd0
|
|
7
|
+
data.tar.gz: 00f7382d4b5ea05c057c3ba77cf6289d3fe96e5a74351b5cc5280d8106240add688156b2b2a76ae1c609bb4c330bbec60745185a9abb1640bde2e5499c040218
|
|
@@ -57,23 +57,15 @@ module BreakerMachines
|
|
|
57
57
|
|
|
58
58
|
# Execute a block with circuit breaker protection
|
|
59
59
|
#
|
|
60
|
+
# Admission, the open -> half-open cooldown, and half-open probe limits run
|
|
61
|
+
# in the native circuit. A StandardError counts as a failure and is
|
|
62
|
+
# re-raised; other exceptions and throw/break pass through uncounted.
|
|
63
|
+
#
|
|
60
64
|
# @yield Block to execute
|
|
61
65
|
# @return Result of the block
|
|
62
|
-
# @raise [CircuitOpenError] if circuit is open
|
|
63
|
-
def call
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
start_time = BreakerMachines.monotonic_time
|
|
67
|
-
begin
|
|
68
|
-
result = yield
|
|
69
|
-
duration = BreakerMachines.monotonic_time - start_time
|
|
70
|
-
@native_circuit.record_success(duration)
|
|
71
|
-
result
|
|
72
|
-
rescue StandardError => _e
|
|
73
|
-
duration = BreakerMachines.monotonic_time - start_time
|
|
74
|
-
@native_circuit.record_failure(duration)
|
|
75
|
-
raise
|
|
76
|
-
end
|
|
66
|
+
# @raise [CircuitOpenError] if circuit is open or its probe slots are taken
|
|
67
|
+
def call(&)
|
|
68
|
+
@native_circuit.call(&)
|
|
77
69
|
end
|
|
78
70
|
|
|
79
71
|
# Check if circuit is open
|
|
@@ -88,8 +80,14 @@ module BreakerMachines
|
|
|
88
80
|
@native_circuit.is_closed
|
|
89
81
|
end
|
|
90
82
|
|
|
83
|
+
# Check if circuit is half-open (probing for recovery)
|
|
84
|
+
# @return [Boolean]
|
|
85
|
+
def half_open?
|
|
86
|
+
@native_circuit.is_half_open
|
|
87
|
+
end
|
|
88
|
+
|
|
91
89
|
# Get current state name
|
|
92
|
-
# @return [String] 'open' or '
|
|
90
|
+
# @return [String] 'closed', 'open', or 'half_open'
|
|
93
91
|
def state
|
|
94
92
|
@native_circuit.state_name
|
|
95
93
|
end
|
|
@@ -58,10 +58,12 @@ module BreakerMachines
|
|
|
58
58
|
timestamp: current_time
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
#
|
|
62
|
-
|
|
61
|
+
# Keep 5 minutes of history. Events are appended oldest first, so only
|
|
62
|
+
# scan once the oldest has aged out; scanning on every write made each
|
|
63
|
+
# write O(n) once more than 100 events were retained.
|
|
64
|
+
cutoff_time = current_time - 300
|
|
65
|
+
return unless events.size > 100 && events.first[:timestamp] < cutoff_time
|
|
63
66
|
|
|
64
|
-
cutoff_time = current_time - 300 # Keep 5 minutes of history
|
|
65
67
|
events.delete_if { |e| e[:timestamp] < cutoff_time }
|
|
66
68
|
end
|
|
67
69
|
|