circuitbox 1.0.2 → 1.0.3
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/README.md +10 -1
- data/lib/circuitbox.rb +1 -1
- data/lib/circuitbox/excon_middleware.rb +1 -1
- data/lib/circuitbox/faraday_middleware.rb +1 -1
- data/lib/circuitbox/version.rb +1 -1
- data/test/circuit_breaker_test.rb +7 -33
- 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: f75524d25326132f1bac120effbfa9b130f95bf1
|
4
|
+
data.tar.gz: ee8a589ff7b55ea95f5e5d119e7c30fe7be4e640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 280e82433f43b428b48ee4e5a5a713da46deb723f8df9d886b3e2bf1e7eb922a119c367a706f66d82ee5d731090580773de06030f451ea40784ae544218e1953
|
7
|
+
data.tar.gz: 1b64ba171cfe40c0956ed38f94cc3e37c3e848a051cc987a2944b7578362ab5f51992757208dea50559cb5338d3fcff9c7fa2537ba9df047bfb05f1dabbc4038
|
data/README.md
CHANGED
@@ -218,9 +218,12 @@ use with Unicorn. It depends on the `daybreak` gem.
|
|
218
218
|
|
219
219
|
```ruby
|
220
220
|
require "daybreak"
|
221
|
-
Circuitbox.circuit :identifier, cache: Moneta.new(:Daybreak, file: "db.daybreak")
|
221
|
+
Circuitbox.circuit :identifier, cache: Moneta.new(:Daybreak, file: "db.daybreak", expires: true)
|
222
222
|
```
|
223
223
|
|
224
|
+
It is important for the store to have
|
225
|
+
[expires](https://github.com/minad/moneta#backend-feature-matrix) support.
|
226
|
+
|
224
227
|
## Faraday
|
225
228
|
|
226
229
|
Circuitbox ships with [Faraday HTTP client](https://github.com/lostisland/faraday) middleware.
|
@@ -297,6 +300,12 @@ c.use Circuitbox::FaradayMiddleware, open_circuit: lambda { |response| response.
|
|
297
300
|
## CHANGELOG
|
298
301
|
### version next
|
299
302
|
|
303
|
+
### v1.0.3
|
304
|
+
- fix timeout issue for default configuration, as default `:Memory` adapter does
|
305
|
+
not natively support expires, we need to actually load it on demand.
|
306
|
+
- fix memoization of `circuit_breaker_options` not actually doing memoization in
|
307
|
+
`excon` and `faraday` middleware.
|
308
|
+
|
300
309
|
### v1.0.2
|
301
310
|
- Fix timeout issue [#51](https://github.com/yammer/circuitbox/issues/51)
|
302
311
|
[sebastian-juliu](https://github.com/sebastian-julius)
|
data/lib/circuitbox.rb
CHANGED
@@ -86,7 +86,7 @@ class Circuitbox
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def circuit_breaker_options
|
89
|
-
return @circuit_breaker_options if @
|
89
|
+
return @circuit_breaker_options if @circuit_breaker_options
|
90
90
|
|
91
91
|
@circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
|
92
92
|
@circuit_breaker_options.merge!(
|
@@ -63,7 +63,7 @@ class Circuitbox
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def circuit_breaker_options
|
66
|
-
return @circuit_breaker_options if @
|
66
|
+
return @circuit_breaker_options if @circuit_breaker_options
|
67
67
|
|
68
68
|
@circuit_breaker_options = opts.fetch(:circuit_breaker_options, {})
|
69
69
|
@circuit_breaker_options.merge!(
|
data/lib/circuitbox/version.rb
CHANGED
@@ -151,55 +151,29 @@ class CircuitBreakerTest < Minitest::Test
|
|
151
151
|
end
|
152
152
|
|
153
153
|
describe 'closing the circuit after sleep' do
|
154
|
-
class GodTime < SimpleDelegator
|
155
|
-
def now
|
156
|
-
self
|
157
|
-
end
|
158
|
-
|
159
|
-
def initialize(now=nil)
|
160
|
-
@now = now || Time.now
|
161
|
-
super(@now)
|
162
|
-
end
|
163
|
-
|
164
|
-
def __getobj__
|
165
|
-
@now
|
166
|
-
end
|
167
|
-
|
168
|
-
def __setobj__(obj)
|
169
|
-
@now = obj
|
170
|
-
end
|
171
|
-
|
172
|
-
def jump(interval)
|
173
|
-
__setobj__ @now + interval
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
154
|
def cb_options
|
178
155
|
{
|
179
|
-
sleep_window:
|
180
|
-
time_window:
|
156
|
+
sleep_window: 1,
|
157
|
+
time_window: 2,
|
181
158
|
volume_threshold: 5,
|
182
|
-
error_threshold:
|
183
|
-
timeout_seconds: 1
|
184
|
-
time_class: @timer
|
159
|
+
error_threshold: 5,
|
160
|
+
timeout_seconds: 1
|
185
161
|
}
|
186
162
|
end
|
187
163
|
|
188
164
|
def setup
|
189
|
-
@timer = GodTime.new
|
190
165
|
@circuit = Circuitbox::CircuitBreaker.new(:yammer, cb_options)
|
191
166
|
end
|
192
167
|
|
193
|
-
|
194
168
|
it 'close the circuit after sleeping time' do
|
195
169
|
# lets open the circuit
|
196
|
-
|
170
|
+
(cb_options[:error_threshold] + 1).times { @circuit.run { raise RequestFailureError } }
|
197
171
|
run_count = 0
|
198
172
|
@circuit.run { run_count += 1 }
|
199
173
|
assert_equal 0, run_count, 'circuit is not open'
|
174
|
+
# it is + 2 on purpose, because + 1 is flaky here
|
175
|
+
sleep cb_options[:sleep_window] + 2
|
200
176
|
|
201
|
-
@timer.jump(cb_options[:sleep_window] + 1)
|
202
|
-
@circuit.try_close_next_time
|
203
177
|
@circuit.run { run_count += 1 }
|
204
178
|
assert_equal 1, run_count, 'circuit is not closed'
|
205
179
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuitbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fahim Ferdous
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|