Comparing version 3.5.0 to 4.0.0
@@ -12,6 +12,6 @@ /// <reference types="node" /> | ||
export declare class Disyuntor extends EventEmitter { | ||
private params; | ||
private config; | ||
failures: number; | ||
lastFailure: number; | ||
currentCooldown?: number; | ||
currentCooldown: number; | ||
get timeout(): number; | ||
@@ -24,3 +24,3 @@ constructor(params: Options.Parameters); | ||
export declare function wrapCallbackApi<T extends (...args: any[]) => void>(params: Options.Parameters, call: T, thisParam?: any): T; | ||
export declare function wrapPromise<A, T extends PromiseBuilder<A>>(params: Options.Parameters, call: T): (...args: any[]) => Promise<{} | A>; | ||
export declare function wrapPromise<A, T extends PromiseBuilder<A>>(params: Options.Parameters, call: T): (...args: any[]) => Promise<A>; | ||
export { DisyuntorError, Options }; |
@@ -11,19 +11,9 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DisyuntorError = exports.wrapPromise = exports.wrapCallbackApi = exports.Disyuntor = void 0; | ||
const events_1 = require("events"); | ||
const ms_1 = __importDefault(require("ms")); | ||
const DisyuntorError_1 = require("./DisyuntorError"); | ||
Object.defineProperty(exports, "DisyuntorError", { enumerable: true, get: function () { return DisyuntorError_1.DisyuntorError; } }); | ||
const Timeout_1 = require("./Timeout"); | ||
const defaults = { | ||
timeout: '2s', | ||
maxFailures: 5, | ||
cooldown: '15s', | ||
maxCooldown: '30s', | ||
trigger: () => true | ||
}; | ||
const Config_1 = require("./Config"); | ||
var State; | ||
@@ -40,29 +30,17 @@ (function (State) { | ||
this.lastFailure = 0; | ||
this.params = Object.assign({}, defaults, params); | ||
if (typeof this.params.name === 'undefined') { | ||
throw new Error('params.name is required'); | ||
} | ||
if (this.params.timeout === true) { | ||
throw new Error('invalid timeout parameter. It should be either a timespan or false.'); | ||
} | ||
if (typeof this.params.timeout === 'string') { | ||
this.params.timeout = ms_1.default(this.params.timeout); | ||
} | ||
if (typeof this.params.cooldown === 'string') { | ||
this.params.cooldown = ms_1.default(this.params.cooldown); | ||
} | ||
if (typeof this.params.maxCooldown === 'string') { | ||
this.params.maxCooldown = ms_1.default(this.params.maxCooldown); | ||
} | ||
this.config = Config_1.DisyuntorConfig.fromParameters(params); | ||
// TODO this is redundant, but necessary for typing. De-dup | ||
this.currentCooldown = this.config.thresholdConfig.minCooldownTimeMs; | ||
this.reset(); | ||
if (typeof this.params.onTrip === 'function') { | ||
this.on('trip', this.params.onTrip); | ||
// TODO move this validation + setup elsewhere | ||
if (typeof this.config.onBreakerTripEvent === 'function') { | ||
this.on('trip', this.config.onBreakerTripEvent); | ||
} | ||
if (typeof this.params.onClose === 'function') { | ||
this.on('close', this.params.onClose); | ||
// TODO move this validation + setup elsewhere | ||
if (typeof this.config.onBreakerCloseEvent === 'function') { | ||
this.on('close', this.config.onBreakerCloseEvent); | ||
} | ||
} | ||
get timeout() { | ||
//this is already parsed | ||
return this.params.timeout; | ||
return this.config.thresholdConfig.callTimeoutMs; | ||
} | ||
@@ -72,6 +50,7 @@ reset() { | ||
this.lastFailure = 0; | ||
this.currentCooldown = this.params.cooldown; | ||
this.currentCooldown = this.config.thresholdConfig.minCooldownTimeMs; | ||
} | ||
get state() { | ||
if (this.failures >= this.params.maxFailures) { | ||
// TODO sliding window? Error rate? more failure recognition algorithms | ||
if (this.failures >= this.config.thresholdConfig.maxConsecutiveFailures) { | ||
const timeSinceLastFailure = Date.now() - this.lastFailure; | ||
@@ -95,6 +74,6 @@ // check to see if this failure has occurred within the cooldown period | ||
if (state === State.Open) { | ||
throw new DisyuntorError_1.DisyuntorError(`${this.params.name}: the circuit-breaker is open`, this.state); | ||
throw new DisyuntorError_1.DisyuntorError(`${this.config.name}: the circuit-breaker is open`, this.state); | ||
} | ||
else if (state === State.HalfOpen) { | ||
this.currentCooldown = Math.min(this.currentCooldown * (this.failures + 1), this.params.maxCooldown); | ||
this.currentCooldown = Math.min(this.currentCooldown * (this.failures + 1), this.config.thresholdConfig.maxCooldownTimeMs); | ||
} | ||
@@ -104,7 +83,7 @@ try { | ||
let result; | ||
if (this.params.timeout === false) { | ||
if (!this.config.thresholdConfig.enforceCallTimeout) { | ||
result = yield promise; | ||
} | ||
else { | ||
const timeout = Timeout_1.create(this.params.name, this.params.timeout, promise); | ||
const timeout = Timeout_1.create(this.config.name, this.config.thresholdConfig.callTimeoutMs, promise); | ||
result = yield Promise.race([timeout, promise]); | ||
@@ -121,6 +100,6 @@ } | ||
catch (err) { | ||
if (this.params.trigger(err)) { | ||
if (this.config.shouldTriggerAsFailure(err)) { | ||
this.failures++; | ||
this.lastFailure = Date.now(); | ||
if (this.failures >= this.params.maxFailures) { | ||
if (this.failures >= this.config.thresholdConfig.maxConsecutiveFailures) { | ||
this.emit('trip', err, this.failures, this.currentCooldown); | ||
@@ -170,6 +149,7 @@ } | ||
return disyuntor.protect(() => __awaiter(this, void 0, void 0, function* () { | ||
var promise = call(...args); | ||
const promise = call(...args); | ||
if (!promise || !promise.then) { | ||
throw new Error(`expecting a promise but got ${{}.toString.call(promise)}`); | ||
} | ||
// TODO is this redundant? | ||
return yield promise; | ||
@@ -180,2 +160,1 @@ })); | ||
exports.wrapPromise = wrapPromise; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGlzeXVudG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL0Rpc3l1bnRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7QUFBQSxtQ0FBcUM7QUFDckMsNENBQW1CO0FBR25CLHFEQUFrRDtBQWtNekMsK0ZBbE1BLCtCQUFjLE9Ba01BO0FBak12Qix1Q0FBb0Q7QUFFcEQsTUFBTSxRQUFRLEdBQUc7SUFDZixPQUFPLEVBQU0sSUFBSTtJQUNqQixXQUFXLEVBQUUsQ0FBQztJQUNkLFFBQVEsRUFBSyxL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BQyxDQUFBLENBQUMsQ0FBQztJQUNMLENBQUMsQ0FBQTtBQUNILENBQUM7QUFqQkQsa0NBaUJDIn0= |
@@ -14,2 +14,1 @@ "use strict"; | ||
exports.DisyuntorError = DisyuntorError; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGlzeXVudG9yRXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvRGlzeXVudG9yRXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsTUFBYSxjQUFlLFNBQVEsS0FBSztJQUN2QyxZQUNTLE9BQWUsRUFDZixNQUFjO1FBQ3JCLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUZSLFlBQU8sR0FBUCxPQUFPLENBQVE7UUFDZixXQUFNLEdBQU4sTUFBTSxDQUFRO1FBRXJCLE1BQU0sQ0FBQyxjQUFjLENBQUMsSUFBSSxFQUFFLGNBQWMsQ0FBQyxTQUFTLENBQUMsQ0FBQztRQUN0RCxLQUFLLENBQUMsaUJBQWlCLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtJQUNqRCxDQUFDO0NBQ0Y7QUFSRCx3Q0FRQyJ9 |
@@ -46,4 +46,3 @@ export declare namespace Options { | ||
trigger?(err: Error): boolean; | ||
[key: string]: string | Function | number | boolean; | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3B0aW9ucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9PcHRpb25zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ== |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.create = exports.TimeoutError = void 0; | ||
// import Promise from 'bluebird' | ||
const DisyuntorError_1 = require("./DisyuntorError"); | ||
@@ -20,2 +19,3 @@ class TimeoutError extends DisyuntorError_1.DisyuntorError { | ||
}); | ||
//@ts-ignore | ||
this.onCancel = onCancel; | ||
@@ -32,2 +32,3 @@ } | ||
}, milliseconds); | ||
//@ts-ignore | ||
onCancel(() => clearTimeout(timeout)); | ||
@@ -41,2 +42,1 @@ }); | ||
exports.create = create; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVGltZW91dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9UaW1lb3V0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlDQUFpQztBQUNqQyxxREFBaUQ7QUFFakQsTUFBYSxZQUFhLFNBQVEsK0JBQWM7SUFDOUMsWUFBWSxJQUFZLEVBQUUsWUFBb0I7UUFDNUMsS0FBSyxDQUFDLEdBQUcsSUFBSSwwQkFBMEIsWUFBWSxnQkFBZ0IsRUFBRSxTQUFTLENBQUMsQ0FBQztRQUNoRixNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksRUFBRSxZQUFZLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDcEQsS0FBSyxDQUFDLGlCQUFpQixDQUFDLElBQUksRUFBRSxJQUFJLENBQUMsV0FBVyxDQUFDLENBQUE7SUFDakQsQ0FBQztDQUNGO0FBTkQsb0NBTUM7QUFFRCxNQUFNLGtCQUFzQixTQUFRLE9BQVU7SUFHNUMsWUFBWSxRQUEySTtRQUNySixJQUFJLFFBQW9CLENBQUM7UUFDekIsS0FBSyxDQUFDLENBQUMsT0FBTyxFQUFFLE1BQU0sRUFBRSxFQUFFO1lBQ3hCLFFBQVEsQ0FBQyxPQUFPLEVBQUUsTUFBTSxFQUFFLENBQUMsQ0FBQyxFQUFFLENBQUMsUUFBUSxHQUFHLENBQUMsQ0FBQyxDQUFDO1FBQy9DLENBQUMsQ0FBQyxDQUFDO1FBQ0gsSUFBSSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUM7SUFDM0IsQ0FBQztJQUVELE1BQU07UUFDSixJQUFJLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDbEIsQ0FBQztDQUNGO0FBRUQsU0FBZ0IsTUFBTSxDQUFJLElBQVksRUFBRSxZQUFvQixFQUFFLE1BQW9CO0lBQ2hGLElBQUksV0FBVyxHQUFHLElBQUksa0JBQWtCLENBQUksQ0FBQyxRQUFRLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxFQUFFO1FBQ3pFLE1BQU0sT0FBTyxHQUFHLFVBQVUsQ0FBQyxHQUFHLEVBQUU7WUFDOUIsTUFBTSxDQUFDLElBQUksWUFBWSxDQUFDLElBQUksRUFBRSxZQUFZLENBQUMsQ0FBQyxDQUFDO1FBQy9DLENBQUMsRUFBRSxZQUFZLENBQUMsQ0FBQztRQUNqQixRQUFRLENBQUMsR0FBRyxFQUFFLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7SUFDeEMsQ0FBQyxDQUFDLENBQUM7SUFFSCxNQUFNO1NBQ0gsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFDLFdBQVcsQ0FBQyxNQUFNLEVBQUUsQ0FBQztTQUNoQyxLQUFLLENBQUMsR0FBRyxFQUFFLENBQUMsV0FBVyxDQUFDLE1BQU0sRUFBRSxDQUFDLENBQUM7SUFFckMsT0FBTyxXQUFXLENBQUM7QUFDckIsQ0FBQztBQWJELHdCQWFDIn0= |
{ | ||
"name": "disyuntor", | ||
"description": "A circuit-breaker implementation with exponential backoff.", | ||
"version": "3.5.0", | ||
"version": "4.0.0", | ||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)", | ||
@@ -15,3 +15,3 @@ "repository": { | ||
"prepare": "tsc", | ||
"test": "nyc mocha" | ||
"test": "npx jest --coverage" | ||
}, | ||
@@ -22,4 +22,6 @@ "dependencies": { | ||
"devDependencies": { | ||
"@istanbuljs/nyc-config-typescript": "^0.1.3", | ||
"@types/async": "^3.2.5", | ||
"@types/bluebird": "^3.5.24", | ||
"@types/chai": "^4.2.14", | ||
"@types/jest": "^26.0.20", | ||
"@types/ms": "^0.7.30", | ||
@@ -30,16 +32,8 @@ "@types/node": "^12.9.0", | ||
"chai": "~2.3.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^14.1.1", | ||
"jest": "^26.6.3", | ||
"source-map-support": "^0.5.13", | ||
"ts-jest": "^26.5.0", | ||
"ts-node": "^7.0.1", | ||
"typescript": "^4.1.3" | ||
}, | ||
"nyc": { | ||
"extends": "@istanbuljs/nyc-config-typescript", | ||
"all": true, | ||
"reporter": [ | ||
"text", | ||
"lcov" | ||
] | ||
}, | ||
"files": [ | ||
@@ -46,0 +40,0 @@ "lib/**/*" |
@@ -13,5 +13,5 @@ [![Build Status](https://travis-ci.org/auth0/disyuntor.svg?branch=master)](https://travis-ci.org/auth0/disyuntor) | ||
Once the protected function returns more than `maxFailures`, the breaker trips and every call made during the `cooldown` interval will immdiately return an error preventing resource depletion. This is known as the `open` state. | ||
Once the protected function returns more than `maxFailures`, the breaker trips and every call made during the `cooldown` interval will immediately return an error preventing resource depletion. This is known as the `open` state. | ||
Once the system has settled it will allow one call to go to the protected function. If the call succeds the breaker will be reset to its `closed` state otherwise it will continue `open`. This state is known as `half open` | ||
Once the system has settled it will allow one call to go to the protected function. If the call succeeds the breaker will be reset to its `closed` state otherwise it will continue `open`. This state is known as `half open` | ||
@@ -18,0 +18,0 @@ A call is considered to have failed if the callback is not called before the `timeout` or if it is called with the first (error) parameter. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
23155
14
402