Comparing version 1.11.0 to 1.11.1
@@ -1,5 +0,29 @@ | ||
# Change Log | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
### [1.11.1](https://github.com/nodeshift/opossum/compare/v1.11.0...v1.11.1) (2019-05-22) | ||
### Build System | ||
* don't fail coverage from untrusted forks ([194e18d](https://github.com/nodeshift/opossum/commit/194e18d)) | ||
* remove travis-ci now that circleci is good ([9756bf5](https://github.com/nodeshift/opossum/commit/9756bf5)) | ||
* rename the workflow to test_node_versions in circleci ([c7cc277](https://github.com/nodeshift/opossum/commit/c7cc277)) | ||
* set circleci to ignore gh-pages branch ([23e1384](https://github.com/nodeshift/opossum/commit/23e1384)) | ||
* set up coveralls (again); remove Makefile ([d099b45](https://github.com/nodeshift/opossum/commit/d099b45)) | ||
* switch to standardx for linting ([4967736](https://github.com/nodeshift/opossum/commit/4967736)) | ||
* try circleci for continuous integration ([1a77f3a](https://github.com/nodeshift/opossum/commit/1a77f3a)) | ||
* try workflows for multiple version builds ([5e9e6c8](https://github.com/nodeshift/opossum/commit/5e9e6c8)) | ||
* use codacy for coverage instead of coveralls ([e359ab9](https://github.com/nodeshift/opossum/commit/e359ab9)) | ||
### Tests | ||
* generate browser/headless test suite ([2d24b35](https://github.com/nodeshift/opossum/commit/2d24b35)) | ||
* improve circuit.shutdown() test ([6841abc](https://github.com/nodeshift/opossum/commit/6841abc)) | ||
* switch to serve instead of http-server for browser tests ([50ccab7](https://github.com/nodeshift/opossum/commit/50ccab7)) | ||
# [1.11.0](https://github.com/nodeshift/opossum/compare/v1.10.1...v1.11.0) (2019-03-14) | ||
@@ -6,0 +30,0 @@ |
98
index.js
@@ -12,40 +12,40 @@ 'use strict'; | ||
/** | ||
* @module opossum | ||
*/ | ||
/** | ||
* Creates a {@link CircuitBreaker} instance capable of executing `action`. | ||
* @param action {function} The action to fire for this {@link CircuitBreaker} | ||
* @param options {Object} Options for the {@link CircuitBreaker} | ||
* @param options.timeout {number} The time in milliseconds that action should | ||
* | ||
* @param {Function} action The action to fire for this {@link CircuitBreaker} | ||
* @param {Object} options Options for the {@link CircuitBreaker} | ||
* @param {Number} options.timeout The time in milliseconds that action should | ||
* be allowed to execute before timing out. Default 10000 (10 seconds) | ||
* @param options.maxFailures The number of times the circuit can fail before | ||
* opening. Default 10. | ||
* @param options.resetTimeout The time in milliseconds to wait before setting | ||
* 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 | ||
* @param {Number} options.maxFailures The number of times the circuit can fail | ||
* before opening. Default 10. | ||
* @param {Number} options.resetTimeout The time in milliseconds to wait before | ||
* setting the breaker to `halfOpen` state, and trying the action again. | ||
* @param {Number} 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 {Number} 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 {String} options.name the circuit name to use when reporting stats | ||
* @param {boolean} 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 {Number} 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 {Number} options.errorThresholdPercentage the error percentage at | ||
* which to open the circuit and start short-circuiting requests to fallback. | ||
* @param {boolean} options.enabled whether this circuit is enabled upon | ||
* construction. Default: true | ||
* @param {boolean} options.allowWarmUp 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 | ||
* @param options.volumeThreshold {Number} the minimum number of requests within | ||
* 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 | ||
* @param {Number} options.volumeThreshold the minimum number of requests within | ||
* the rolling statistical window that must exist before the circuit breaker | ||
@@ -55,3 +55,3 @@ * can open. This is similar to `options.allowWarmUp` in that no matter how many | ||
* does not exceed this threshold, the circuit will remain closed. Default: 0 | ||
* @param options.errorFilter {Function} an optional function that will be | ||
* @param {Function} options.errorFilter an optional function that will be | ||
* called when the circuit's function fails (returns a rejected Promise). If | ||
@@ -62,5 +62,5 @@ * this function returns truthy, the circuit's failure statistics will not be | ||
* @return a {@link CircuitBreaker} instance | ||
* @return {CircuitBreaker} a newly created {@link CircuitBreaker} instance | ||
*/ | ||
function circuitBreaker (action, options) { | ||
function factory (action, options) { | ||
return new CircuitBreaker(action, Object.assign({}, defaults, options)); | ||
@@ -74,6 +74,5 @@ } | ||
* callback is executed. | ||
* @function promisify | ||
* @function factory.promisify | ||
* | ||
* @param action {function} A Node.js-like asynchronous function | ||
* @return The `action` wrapped in a promise API. | ||
* @param {Function} action A Node.js-like asynchronous function | ||
* @example | ||
@@ -84,8 +83,17 @@ * const fs = require('fs'); | ||
*/ | ||
circuitBreaker.promisify = require('./lib/promisify'); | ||
factory.promisify = require('./lib/promisify'); | ||
let warningIssued = false; | ||
Object.defineProperty(factory, 'stats', { | ||
get: _ => { | ||
if (!warningIssued) { | ||
warningIssued = true; | ||
console.warn(`WARNING: Hystrics stats are deprecated | ||
See: https://github.com/Netflix/Hystrix#dashboard`) | ||
} | ||
return require('./lib/hystrix-stats').stream; | ||
} | ||
}); | ||
circuitBreaker.stats = require('./lib/hystrix-stats').stream; | ||
module.exports = exports = circuitBreaker; | ||
module.exports = exports = factory; | ||
// Allow use of default import syntax in TypeScript | ||
module.exports.default = circuitBreaker; | ||
module.exports.default = factory; |
@@ -26,2 +26,5 @@ 'use strict'; | ||
let warningIssued = false; | ||
/** | ||
@@ -32,42 +35,37 @@ * Constructs a {@link CircuitBreaker}. | ||
* @extends EventEmitter | ||
* @param action {Function} The action to fire for this {@link CircuitBreaker} | ||
* @param options {Object} Options for the {@link CircuitBreaker}. | ||
* There are **no default options** when you use the constructor directly. You | ||
* must supply values for each of these. | ||
* @param options.timeout {Number} The time in milliseconds that action should | ||
* be allowed to execute before timing out. Timeout can be disabled by setting | ||
* this to `false`. | ||
* @param options.maxFailures {Number} The number of times the circuit can fail | ||
* before opening. | ||
* (deprecated - see {CircuitBreaker#options.errorThresholdPercentage}) | ||
* @param options.resetTimeout {Number} The time in milliseconds to wait before | ||
* @param {Function} action The action to fire for this {@link CircuitBreaker} | ||
* @param {Object} options Options for the {@link CircuitBreaker} | ||
* @param {Number} options.timeout The time in milliseconds that action should | ||
* be allowed to execute before timing out. Default 10000 (10 seconds) | ||
* @param {Number} options.maxFailures The number of times the circuit can fail | ||
* before opening. Default 10. | ||
* @param {Number} options.resetTimeout The time in milliseconds to wait before | ||
* setting the breaker to `halfOpen` state, and trying the action again. | ||
* @param options.rollingCountTimeout {Number} Sets the duration of the | ||
* @param {Number} 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 {Number} 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 {String} the circuit name to use when reporting stats | ||
* @param options.rollingPercentilesEnabled {Boolean} 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. | ||
* @param options.capacity {Number} 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 {Number} the error percentage at | ||
* @param {Number} options.rollingCountBuckets Sets the number of buckets the | ||
* statistical window is divided into. So, if options.rollingCountTimeout is | ||
* 10000, and options.rollingCountBuckets is 10, the statistical window will | ||
* be 1000 1 second snapshots in the statistical window. Default: 10 | ||
* @param {String} options.name the circuit name to use when reporting stats | ||
* @param {boolean} options.rollingPercentilesEnabled 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 {Number} options.capacity the number of concurrent requests allowed. | ||
* If the number currently executing functions is equal to options.capacity, | ||
* further calls to `fire()` are rejected until at least one of the current | ||
* requests completes. | ||
* @param {Number} options.errorThresholdPercentage the error percentage at | ||
* which to open the circuit and start short-circuiting requests to fallback. | ||
* @param options.enabled {boolean} whether this circuit is enabled upon | ||
* @param {boolean} options.enabled whether this circuit is enabled upon | ||
* construction. Default: true | ||
* @param options.allowWarmUp {boolean} determines whether to allow failures | ||
* @param {boolean} options.allowWarmUp 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 | ||
* @param options.volumeThreshold {Number} the minimum number of requests within | ||
* 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 | ||
* @param {Number} options.volumeThreshold the minimum number of requests within | ||
* the rolling statistical window that must exist before the circuit breaker | ||
@@ -77,3 +75,3 @@ * can open. This is similar to `options.allowWarmUp` in that no matter how many | ||
* does not exceed this threshold, the circuit will remain closed. Default: 0 | ||
* @param options.errorFilter {Function} an optional function that will be | ||
* @param {Function} options.errorFilter an optional function that will be | ||
* called when the circuit's function fails (returns a rejected Promise). If | ||
@@ -83,2 +81,16 @@ * this function returns truthy, the circuit's failure statistics will not be | ||
* trip the circuit, but still want to handle it as a failure case. | ||
* | ||
* @fires CircuitBreaker#halfOpen | ||
* @fires CircuitBreaker#close | ||
* @fires CircuitBreaker#open | ||
* @fires CircuitBreaker#fire | ||
* @fires CircuitBreaker#cacheHit | ||
* @fires CircuitBreaker#cacheMiss | ||
* @fires CircuitBreaker#reject | ||
* @fires CircuitBreaker#timeout | ||
* @fires CircuitBreaker#success | ||
* @fires CircuitBreaker#semaphore-locked | ||
* @fires CircuitBreaker#health-check-failed | ||
* @fires CircuitBreaker#fallback | ||
* @fires CircuitBreaker#failure | ||
*/ | ||
@@ -93,3 +105,4 @@ class CircuitBreaker extends EventEmitter { | ||
options.rollingPercentilesEnabled !== false; | ||
this.options.capacity = Number.isInteger(options.capacity) ? options.capacity : Number.MAX_SAFE_INTEGER; | ||
this.options.capacity = Number.isInteger(options.capacity) | ||
? options.capacity : Number.MAX_SAFE_INTEGER; | ||
this.options.errorFilter = options.errorFilter || (_ => false); | ||
@@ -99,3 +112,4 @@ | ||
this[VOLUME_THRESHOLD] = Number.isInteger(options.volumeThreshold) ? options.volumeThreshold : 0; | ||
this[VOLUME_THRESHOLD] = Number.isInteger(options.volumeThreshold) | ||
? options.volumeThreshold : 0; | ||
this[WARMING_UP] = options.allowWarmUp === true; | ||
@@ -143,4 +157,7 @@ this[STATUS] = new Status(this.options); | ||
* successful, the circuit will be closed. Otherwise it remains open. | ||
* | ||
* @event CircuitBreaker#halfOpen | ||
* @type {Number} how long the circuit remained open | ||
*/ | ||
function _startTimer (circuit) { | ||
@@ -172,2 +189,3 @@ return _ => { | ||
* @fires CircuitBreaker#close | ||
* @returns {void} | ||
*/ | ||
@@ -191,2 +209,3 @@ close () { | ||
* @fires CircuitBreaker#open | ||
* @returns {void} | ||
*/ | ||
@@ -209,2 +228,3 @@ open () { | ||
* circuit will fail, returning a rejected promise. | ||
* @returns {void} | ||
*/ | ||
@@ -221,2 +241,3 @@ shutdown () { | ||
* Determines if the circuit has been shutdown. | ||
* @type {Boolean} | ||
*/ | ||
@@ -229,2 +250,3 @@ get isShutdown () { | ||
* Gets the name of this circuit | ||
* @type {String} | ||
*/ | ||
@@ -235,2 +257,6 @@ get name () { | ||
/** | ||
* Gets the name of this circuit group | ||
* @type {String} | ||
*/ | ||
get group () { | ||
@@ -240,2 +266,6 @@ return this[GROUP]; | ||
/** | ||
* Gets whether this cicruit is in the `pendingClosed` state | ||
* @type {Boolean} | ||
*/ | ||
get pendingClose () { | ||
@@ -247,2 +277,3 @@ return this[PENDING_CLOSE]; | ||
* True if the circuit is currently closed. False otherwise. | ||
* @type {Boolean} | ||
*/ | ||
@@ -255,2 +286,3 @@ get closed () { | ||
* True if the circuit is currently opened. False otherwise. | ||
* @type {Boolean} | ||
*/ | ||
@@ -263,2 +295,3 @@ get opened () { | ||
* True if the circuit is currently half opened. False otherwise. | ||
* @type {Boolean} | ||
*/ | ||
@@ -271,2 +304,3 @@ get halfOpen () { | ||
* The current {@link Status} of this {@link CircuitBreaker} | ||
* @type {Status} | ||
*/ | ||
@@ -278,4 +312,5 @@ get status () { | ||
/** | ||
* A convenience function that returns the current stats for the circuit. | ||
* Get the current stats for the circuit. | ||
* @see Status#stats | ||
* @type {Object} | ||
*/ | ||
@@ -285,10 +320,20 @@ get stats () { | ||
} | ||
/** | ||
* A convenience function that returns the hystrixStats. | ||
* Get the hystrixStats. | ||
* @type {HystrixStats} | ||
*/ | ||
get hystrixStats () { | ||
if (!warningIssued) { | ||
warningIssued = true; | ||
console.warn(`WARNING: Hystrics stats are deprecated | ||
See: https://github.com/Netflix/Hystrix#dashboard`) | ||
} | ||
return this[HYSTRIX_STATS]; | ||
} | ||
/** | ||
* Gets whether the circuit is enabled or not | ||
* @type {Boolean} | ||
*/ | ||
get enabled () { | ||
@@ -298,2 +343,6 @@ return this[ENABLED]; | ||
/** | ||
* Gets whether the circuit is currently in warm up phase | ||
* @type {Boolean} | ||
*/ | ||
get warmUp () { | ||
@@ -303,2 +352,6 @@ return this[WARMING_UP]; | ||
/** | ||
* Gets the volume threshold for this circuit | ||
* @type {Boolean} | ||
*/ | ||
get volumeThreshold () { | ||
@@ -313,5 +366,5 @@ return this[VOLUME_THRESHOLD]; | ||
* a rejected Promise. | ||
* @param func {Function | CircuitBreaker} the fallback function to execute | ||
* @param {Function | CircuitBreaker} func the fallback function to execute | ||
* when the breaker has opened or when a timeout or error occurs. | ||
* @return {@link CircuitBreaker} this | ||
* @return {CircuitBreaker} this | ||
*/ | ||
@@ -335,4 +388,4 @@ fallback (func) { | ||
* | ||
* @return a Promise which resolves on success and is rejected | ||
* on failure of the action. | ||
* @return {Promise<any>} promise resolves with the circuit function's return | ||
* value on success or is rejected on failure of the action. | ||
* | ||
@@ -358,2 +411,3 @@ * @fires CircuitBreaker#failure | ||
* @event CircuitBreaker#fire | ||
* @type {any} the arguments passed to the fired fuction | ||
*/ | ||
@@ -379,5 +433,2 @@ this.emit('fire', args); | ||
/** | ||
* https://github.com/nodeshift/opossum/issues/136 | ||
*/ | ||
if (!this[ENABLED]) { | ||
@@ -394,2 +445,3 @@ const result = this.action.apply(this.action, args); | ||
* @event CircuitBreaker#reject | ||
* @type {Error} | ||
*/ | ||
@@ -422,2 +474,3 @@ const error = new Error('Breaker is open'); | ||
* @event CircuitBreaker#timeout | ||
* @type {Error} | ||
*/ | ||
@@ -444,2 +497,3 @@ const latency = Date.now() - latencyStartTime; | ||
* @event CircuitBreaker#success | ||
* @type {any} the return value from the circuit | ||
*/ | ||
@@ -475,2 +529,3 @@ this.emit('success', result, (Date.now() - latencyStartTime)); | ||
* @event CircuitBreaker#semaphore-locked | ||
* @type {Error} | ||
*/ | ||
@@ -485,2 +540,3 @@ this.emit('semaphore-locked', err, latency); | ||
* Clears the cache of this {@link CircuitBreaker} | ||
* @returns {void} | ||
*/ | ||
@@ -502,10 +558,10 @@ clearCache () { | ||
* | ||
* @param func {Function} a health check function which returns a promise. | ||
* @param [interval] {Number} the amount of time between calls to the health | ||
* @param {Function} func a health check function which returns a promise. | ||
* @param {Number} [interval] the amount of time between calls to the health | ||
* check function. Default: 5000 (5 seconds) | ||
* | ||
* @returns {Promise} | ||
* @returns {void} | ||
* | ||
* @fires CircuitBreaker#health-check-failed | ||
* @throws TypeError if `interval` is supplied but not a number | ||
* @throws {TypeError} if `interval` is supplied but not a number | ||
*/ | ||
@@ -527,2 +583,3 @@ healthCheck (func, interval) { | ||
* @event CircuitBreaker#health-check-failed | ||
* @type {Error} | ||
*/ | ||
@@ -546,2 +603,3 @@ this.emit('health-check-failed', e); | ||
* a noop. | ||
* @returns {void} | ||
*/ | ||
@@ -555,2 +613,3 @@ enable () { | ||
* to be executed without circuit or fallback protection. | ||
* @returns {void} | ||
*/ | ||
@@ -573,6 +632,8 @@ disable () { | ||
const result = | ||
circuit[FALLBACK_FUNCTION].apply(circuit[FALLBACK_FUNCTION], [...args, err]); | ||
circuit[FALLBACK_FUNCTION] | ||
.apply(circuit[FALLBACK_FUNCTION], [...args, err]); | ||
/** | ||
* Emitted when the circuit breaker executes a fallback function | ||
* @event CircuitBreaker#fallback | ||
* @type {any} the return value of the fallback function | ||
*/ | ||
@@ -591,2 +652,3 @@ circuit.emit('fallback', result, err); | ||
* @event CircuitBreaker#failure | ||
* @type {Error} | ||
*/ | ||
@@ -593,0 +655,0 @@ circuit.emit('failure', err, latency); |
@@ -17,15 +17,12 @@ 'use strict'; | ||
/** | ||
* @class | ||
* <p> | ||
* Stream Hystrix Metrics for a given {@link CircuitBreaker}. | ||
* A HystrixStats instance is created for every {@link CircuitBreaker} | ||
* and does not typically need to be created by a user. | ||
* </p> | ||
* <p> | ||
* | ||
* A HystrixStats instance will listen for all events on the | ||
* {@link CircuitBreaker.status.snapshot} | ||
* {@link Status#snapshot} | ||
* and format the data to the proper Hystrix format. | ||
* Making it easy to construct an Event Stream for a client | ||
* </p> | ||
* | ||
* @class HystrixStats | ||
* @example | ||
@@ -35,2 +32,3 @@ * const circuit = circuitBreaker(fs.readFile, {}); | ||
* circuit.hystrixStats.getHystrixStream().pipe(response); | ||
* @param {CircuitBreaker} the circuit breaker | ||
* @see CircuitBreaker#hystrixStats | ||
@@ -64,2 +62,3 @@ */ | ||
A convenience function that returns the hystrixStream | ||
@returns {ReadableStream} the statistics stream | ||
*/ | ||
@@ -74,2 +73,3 @@ getHystrixStream () { | ||
* its HystrixStats instance to avoid memory leaks. | ||
* @returns {void} | ||
*/ | ||
@@ -76,0 +76,0 @@ shutdown () { |
@@ -11,9 +11,6 @@ 'use strict'; | ||
/** | ||
* @class | ||
* <p> | ||
* Tracks execution status for a given {@link CircuitBreaker}. | ||
* A Status instance is created for every {@link CircuitBreaker} | ||
* and does not typically need to be created by a user. | ||
* </p> | ||
* <p> | ||
* | ||
* A Status instance will listen for all events on the {@link CircuitBreaker} | ||
@@ -24,4 +21,3 @@ * and track them in a rolling statistical window. The window duration is | ||
* each representing the counts for a {@link CircuitBreaker}'s events. | ||
* </p> | ||
* <p> | ||
* | ||
* The array's length is determined by the {@link CircuitBreaker}'s | ||
@@ -31,4 +27,10 @@ * `rollingCountBuckets` option. The duration of each slice of the window | ||
* `rollingCountBuckets`. | ||
* </p> | ||
* | ||
* @class Status | ||
* @extends EventEmitter | ||
* @param {Object} options for the status window | ||
* @param {Number} options.rollingCountBuckets number of buckets in the window | ||
* @param {Number} options.rollingCountTimeout the duration of the window | ||
* @param {Boolean} options.rollingPercentilesEnabled whether to calculate | ||
* percentiles | ||
* @example | ||
@@ -45,17 +47,6 @@ * // Creates a 1 second window consisting of ten time slices, | ||
* circuit.status.window; | ||
* | ||
* @fires Status#snapshot | ||
* @see CircuitBreaker#status | ||
*/ | ||
class Status extends EventEmitter { | ||
/** | ||
* Emitted at each time-slice. Listeners for this | ||
* event will receive a cumulative snapshot of the current status window. | ||
* @see Status#stats | ||
* @event Status#snapshot | ||
*/ | ||
/** | ||
* Constructs a status object for a given circuit breaker | ||
* @param {} options | ||
*/ | ||
constructor (options) { | ||
@@ -83,3 +74,8 @@ super(); | ||
// take snapshots each time the buckets shift | ||
/** | ||
* Emitted at each time-slice. Listeners for this | ||
* event will receive a cumulative snapshot of the current status window. | ||
* @event Status#snapshot | ||
* @type {Object} | ||
*/ | ||
interval = setInterval(_ => this.emit('snapshot', this.stats), | ||
@@ -92,2 +88,3 @@ bucketInterval); | ||
* Get the cumulative stats for the current window | ||
* @type {Object} | ||
*/ | ||
@@ -141,2 +138,3 @@ get stats () { | ||
* Gets the stats window as an array of time-sliced objects. | ||
* @type {Array} | ||
*/ | ||
@@ -143,0 +141,0 @@ get window () { |
{ | ||
"name": "opossum", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"author": "Red Hat, Inc.", | ||
"license": "Apache-2.0", | ||
"support": { | ||
"target": "LTS", | ||
"response": "REGULAR-7", | ||
"backing": "COMPANY" | ||
}, | ||
"scripts": { | ||
@@ -10,14 +15,15 @@ "prebuild": "npm run lint", | ||
"build:browser": "webpack --config=config/webpack.config.js", | ||
"build:docs": "jsdoc --verbose -d docs -t ./node_modules/ink-docstrap/template -R README.md index.js lib", | ||
"pretest": "npm run lint && npm run build:browser", | ||
"test": "npm run test:coverage", | ||
"test:ci": "npm run build && npm run test:headless && npm run test:coverage", | ||
"build:docs": "npm run build:docs:html && npm run build:docs:markdown", | ||
"build:docs:html": "documentation build index.js -f html -o docs --config documentation.yml", | ||
"build:docs:markdown": "documentation build index.js -f md -o docs/opossum.md", | ||
"pretest": "npm run lint", | ||
"test": "nyc tape test/*.js | tap-spec", | ||
"test:headless": "node test/browser/webpack-test.js", | ||
"test:browser": "opener http://localhost:9007/test/browser/index.html && http-server . -p 9007", | ||
"test:coverage": "nyc tape test/*.js | tap-spec", | ||
"prepare": "npm audit && npm run build:browser", | ||
"postpublish": "./publish-docs.sh", | ||
"prerelease": "npm test", | ||
"test:browser": "opener http://localhost:9007/test/browser/index.html && serve . -p 9007", | ||
"coverage": "nyc report && if [ $CODACY_PROJECT_TOKEN'' != '' ] ; then nyc report --reporter=text-lcov | codacy-coverage; fi", | ||
"ci": "npm run build && npm run test && npm run test:headless && npm run coverage", | ||
"prerelease": "npm run ci", | ||
"release": "standard-version -s", | ||
"lint": "semistandard examples/*/*.js test/*.js index.js lib/*.js" | ||
"lint": "standardx test/*.js index.js lib/*.js test/*/*.js", | ||
"clean": "rm -rf node_modules dist/*.js test/browser/webpack-test.js" | ||
}, | ||
@@ -34,3 +40,4 @@ "repository": { | ||
"lib", | ||
"dist" | ||
"dist", | ||
"doc/opossum.md" | ||
], | ||
@@ -40,17 +47,16 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/nodeshift/opossum", | ||
"homepage": "https://nodeshift.dev/opossum", | ||
"devDependencies": { | ||
"http-server": "~0.11.0", | ||
"ink-docstrap": "~1.3.0", | ||
"jsdoc": "3.5.5", | ||
"marked": "~0.6.0", | ||
"moment": "~2.24.0", | ||
"nyc": "~13.3.0", | ||
"codacy-coverage": "^3.4.0", | ||
"coveralls": "^3.0.3", | ||
"documentation": "^11.0.0", | ||
"nyc": "~14.0.0", | ||
"opener": "1.5.1", | ||
"semistandard": "~13.0.1", | ||
"standard-version": "5.0.1", | ||
"serve": "^11.0.0", | ||
"standard-version": "6.0.1", | ||
"standardx": "^3.0.1", | ||
"tap-spec": "~5.0.0", | ||
"tape": "~4.10.1", | ||
"webpack": "~4.29.0", | ||
"webpack-cli": "~3.2.1" | ||
"webpack": "~4.32.0", | ||
"webpack-cli": "~3.3.0" | ||
}, | ||
@@ -57,0 +63,0 @@ "description": "A fail-fast circuit breaker for promises and callbacks", |
@@ -1,5 +0,6 @@ | ||
# opossum | ||
# opossum [![CircleCI](https://circleci.com/gh/nodeshift/opossum/tree/master.svg?style=svg&circle-token=0742302baa8c95cef354997ea52a383d3d078ff1)](https://circleci.com/gh/nodeshift/opossum/tree/master) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/03f9af1e697743edbe91f8d29831a75d)](https://www.codacy.com/app/nodeshift/opossum?utm_source=github.com&utm_medium=referral&utm_content=nodeshift/opossum&utm_campaign=Badge_Grade) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/03f9af1e697743edbe91f8d29831a75d)](https://www.codacy.com/app/nodeshift/opossum?utm_source=github.com&utm_medium=referral&utm_content=nodeshift/opossum&utm_campaign=Badge_Coverage) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/nodeshift/opossum.svg)](https://greenkeeper.io/) | ||
[![Build Status](https://travis-ci.org/nodeshift/opossum.svg?branch=master)](https://travis-ci.org/nodeshift/opossum) | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/opossum/badge.svg)](https://snyk.io/test/npm/opossum) | ||
@@ -23,3 +24,3 @@ [![dependencies Status](https://david-dm.org/nodeshift/opossum/status.svg)](https://david-dm.org/nodeshift/opossum) | ||
| Build: | make | | ||
| Documentation: | https://nodeshift.github.io/opossum/ | | ||
| Documentation: | https://nodeshift.dev/opossum/ | | ||
| Typngs: | https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/opossum | ||
@@ -91,4 +92,4 @@ | Issue tracker: | https://github.com/nodeshift/opossum/issues | | ||
Here is an example using [hapi.js](https://hapijs.com). See the | ||
[examples](https://github.com/nodeshift/opossum/tree/master/examples/) | ||
folder for more detail. | ||
[opossum-examples](https://github.com/nodeshift-starters/opossum-examples/) | ||
repository for more detail. | ||
@@ -156,13 +157,13 @@ Include `opossum.js` in your HTML file. | ||
* `fire` - emitted when the breaker is fired. | ||
* `reject` - emitted when the breaker is open (or halfOpen). | ||
* `timeout` - emitted when the breaker action times out. | ||
* `success` - emitted when the breaker action completes successfully | ||
* `failure` - emitted when the breaker action fails, called with the error | ||
* `open` - emitted when the breaker state changes to `open` | ||
* `close` - emitted when the breaker state changes to `closed` | ||
* `halfOpen` - emitted when the breaker state changes to `halfOpen` | ||
* `fallback` - emitted when the breaker has a fallback function and executes it | ||
* `semaphore-locked` - emitted when the breaker is at capacity and cannot execute the request | ||
* `health-check-failed` - emitted when a user-supplied health check function returns a rejected promise | ||
* `fire` - emitted when the breaker is fired. | ||
* `reject` - emitted when the breaker is open (or halfOpen). | ||
* `timeout` - emitted when the breaker action times out. | ||
* `success` - emitted when the breaker action completes successfully | ||
* `failure` - emitted when the breaker action fails, called with the error | ||
* `open` - emitted when the breaker state changes to `open` | ||
* `close` - emitted when the breaker state changes to `closed` | ||
* `halfOpen` - emitted when the breaker state changes to `halfOpen` | ||
* `fallback` - emitted when the breaker has a fallback function and executes it | ||
* `semaphore-locked` - emitted when the breaker is at capacity and cannot execute the request | ||
* `health-check-failed` - emitted when a user-supplied health check function returns a rejected promise | ||
@@ -271,2 +272,1 @@ Handling events gives a greater level of control over your application behavior. | ||
Or it could be that you have a large test suite which exercises some code that creates `CircuitBreaker`s and does so repeatedly. If the `CircuitBreaker` being created is only needed for the duration of the test, use `circuit.shutdown()` when the circuit is no longer in use to clean up all listeners. | ||
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
1700811
12
16727
18