Comparing version 1.7.1 to 1.8.0
@@ -5,2 +5,18 @@ # Change Log | ||
<a name="1.8.0"></a> | ||
# [1.8.0](https://github.com/bucharest-gold/opossum/compare/v1.7.1...v1.8.0) (2018-10-02) | ||
### Bug Fixes | ||
* changed currentTime to number as specified in the docs ([e816f43](https://github.com/bucharest-gold/opossum/commit/e816f43)) | ||
### Features | ||
* add options.allowWarmUp as a creation option ([#218](https://github.com/bucharest-gold/opossum/issues/218)) ([ff42d1b](https://github.com/bucharest-gold/opossum/commit/ff42d1b)) | ||
* change default capacity from 10 to MAX_SAFE_INTEGER ([4a8b98b](https://github.com/bucharest-gold/opossum/commit/4a8b98b)) | ||
<a name="1.7.1"></a> | ||
@@ -7,0 +23,0 @@ ## [1.7.1](https://github.com/bucharest-gold/opossum/compare/v1.7.0...v1.7.1) (2018-07-18) |
24
index.js
@@ -25,2 +25,26 @@ 'use strict'; | ||
* the breaker to `halfOpen` state, and trying the action again. | ||
* @param options.rollingCountTimeout Sets the duration of the statistical rolling | ||
* window, in milliseconds. This is how long Opossum keeps metrics for the circuit | ||
* breaker to use and for publishing. Default: 10000 | ||
* @param options.rollingCountBuckets Sets the number of buckets the rolling | ||
* statistical window is divided into. So, if options.rollingCountTimeout is | ||
* 10000, and options.rollingCountBuckets is 10, then the statistical window will | ||
* be 1000 1 second snapshots in the statistical window. Default: 10 | ||
* @param options.name the circuit name to use when reporting stats | ||
* @param options.rollingPercentilesEnabled This property indicates whether | ||
* execution latencies should be tracked and calculated as percentiles. If they | ||
* are disabled, all summary statistics (mean, percentiles) are returned as -1. | ||
* Default: false | ||
* @param options.capacity the number of concurrent requests allowed. If the number | ||
* currently executing function calls is equal to options.capacity, further calls | ||
* to `fire()` are rejected until at least one of the current requests completes. | ||
* @param options.errorThresholdPercentage the error percentage at which to open the | ||
* circuit and start short-circuiting requests to fallback. | ||
* @param options.enabled whether this circuit is enabled upon construction. Default: true | ||
* @param options.allowWarmUp {boolean} determines whether to allow failures | ||
* without opening the circuit during a brief warmup period (this is the | ||
* `rollingCountDuration` property). Default: false | ||
* allow before enabling the circuit. This can help in situations where no matter | ||
* what your `errorThresholdPercentage` is, if the first execution times out or | ||
* fails, the circuit immediately opens. Default: 0 | ||
* @return a {@link CircuitBreaker} instance | ||
@@ -27,0 +51,0 @@ */ |
@@ -20,2 +20,3 @@ 'use strict'; | ||
const ENABLED = Symbol('Enabled'); | ||
const WARMING_UP = Symbol('warming-up'); | ||
const deprecation = `options.maxFailures is deprecated. \ | ||
@@ -62,2 +63,8 @@ Please use options.errorThresholdPercentage`; | ||
* construction. Default: true | ||
* @param options.allowWarmUp {boolean} determines whether to allow failures | ||
* without opening the circuit during a brief warmup period (this is the | ||
* `rollingCountDuration` property). Default: false | ||
* allow before enabling the circuit. This can help in situations where no matter | ||
* what your `errorThresholdPercentage` is, if the first execution times out or | ||
* fails, the circuit immediately opens. Default: 0 | ||
*/ | ||
@@ -72,6 +79,7 @@ class CircuitBreaker extends EventEmitter { | ||
options.rollingPercentilesEnabled !== false; | ||
this.options.capacity = | ||
typeof options.capacity === 'number' ? options.capacity : 10; | ||
this.options.capacity = Number.isInteger(options.capacity) ? options.capacity : Number.MAX_SAFE_INTEGER; | ||
this.semaphore = new Semaphore(this.options.capacity); | ||
this[WARMING_UP] = options.allowWarmUp === true; | ||
this[STATUS] = new Status(this.options); | ||
@@ -85,2 +93,10 @@ this[STATE] = CLOSED; | ||
if (this[WARMING_UP]) { | ||
const timer = setTimeout(_ => (this[WARMING_UP] = false), | ||
this.options.rollingCountTimeout); | ||
if (typeof timer.unref === 'function') { | ||
timer.unref(); | ||
} | ||
} | ||
if (typeof action !== 'function') { | ||
@@ -233,2 +249,6 @@ this.action = _ => Promise.resolve(action); | ||
get warmUp () { | ||
return this[WARMING_UP]; | ||
} | ||
/** | ||
@@ -495,2 +515,3 @@ * Provide a fallback function for this {@link CircuitBreaker}. This | ||
circuit.emit('failure', err, latency); | ||
if (circuit.warmUp) return; | ||
@@ -497,0 +518,0 @@ // check stats to see if the circuit should be opened |
@@ -14,3 +14,3 @@ 'use strict'; | ||
group: stats.group, | ||
currentTime: new Date(), | ||
currentTime: Date.now(), | ||
isCircuitBreakerOpen: !stats.closed, | ||
@@ -17,0 +17,0 @@ errorPercentage: |
@@ -90,4 +90,3 @@ 'use strict'; | ||
const totals = this[WINDOW].reduce((acc, val) => { | ||
// the window starts with all but one bucket undefined | ||
if (!val) return acc; | ||
if (!val) { return acc; } | ||
Object.keys(acc).forEach(key => { | ||
@@ -94,0 +93,0 @@ if (key !== 'latencyTimes' && key !== 'percentiles') { |
{ | ||
"name": "opossum", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"author": "Red Hat, Inc.", | ||
@@ -43,7 +43,7 @@ "license": "Apache-2.0", | ||
"jsdoc": "3.5.5", | ||
"marked": "~0.4.0", | ||
"marked": "~0.5.0", | ||
"moment": "~2.22.0", | ||
"nsp": "~3.2.1", | ||
"nyc": "~12.0.2", | ||
"opener": "1.4.3", | ||
"opener": "1.5.1", | ||
"semistandard": "~12.0.1", | ||
@@ -53,4 +53,4 @@ "standard-version": "4.4.0", | ||
"tape": "~4.9.0", | ||
"webpack": "~4.12.0", | ||
"webpack-cli": "~3.0.3" | ||
"webpack": "~4.19.0", | ||
"webpack-cli": "~3.1.0" | ||
}, | ||
@@ -57,0 +57,0 @@ "description": "A fail-fast circuit breaker for promises and callbacks", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1588541
15700