Comparing version 3.3.2 to 3.4.0
@@ -54,2 +54,5 @@ "use strict"; | ||
} | ||
if (typeof this.params.onClose === 'function') { | ||
this.on('close', this.params.onClose); | ||
} | ||
} | ||
@@ -81,2 +84,3 @@ get timeout() { | ||
const state = this.state; | ||
const cooldown = this.currentCooldown; | ||
if (state === State.Open) { | ||
@@ -95,2 +99,5 @@ throw new DisyuntorError_1.DisyuntorError(`${this.params.name}: the circuit-breaker is open`, this.state); | ||
const result = yield Promise.race([timeout, promise]); | ||
if (state === State.HalfOpen) { | ||
this.emit('close', cooldown); | ||
} | ||
//If it worked we need to reset it, regardless if is half-open or closed, | ||
@@ -154,2 +161,2 @@ //the failures counter is meant to accumulate failures in a row. | ||
exports.wrapPromise = wrapPromise; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRGlzeXVudG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL0Rpc3l1bnRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7O0FBQUEsbUNBQXFDO0FBQ3JDLDRDQUFtQjtBQUduQixxREFBa0Q7QUF3S3pDLHlCQXhLQSwrQkFBYyxDQXdLQTtBQXZLdkIsdUNBQW9EO0FBR3BELE1BQU0sUUFBUSxHQUFHO0lBQ2YsT0FBTyxFQUFNLElBQUk7SUFDakIsV0FBVyxFQUFFLENBQUM7SUFDZCxRQUFRLEVBQUssS0FBSztJQUNsQixPQUFPLEVBQU0sR0FBRyxFQUFFLENBQUMsSUFBSTtDQUN4QixDQUFDO0FBRUYsTUFBTSxTQUFTLEdBQUcsQ0FBQyxTQUFTLEVBQUUsVUFBVSxFQUFFLGFBQWEsQ0FBQyxDQUFDO0FBRXpELElBQUssS0FJSjtBQUpELFdBQUssS0FBSztJQUNSLDBCQUFpQixDQUFBO0lBQ2pCLHNCQUFhLENBQUE7SUFDYiwrQkFBc0IsQ0FBQTtBQUN4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Q0FBQyxDQUFBLENBQUMsQ0FBQztJQUNMLENBQUMsQ0FBQTtBQUNILENBQUM7QUFqQkQsa0NBaUJDIn0= |
@@ -36,2 +36,7 @@ export declare namespace Options { | ||
/** | ||
* Callback executed every time the circuit-breaker closes after half-open state. | ||
* @param currentCooldown The amount of milliseconds before closing back. | ||
*/ | ||
onClose?(currentCooldown: number): any; | ||
/** | ||
* Callback executed to verify if an error should trigger the circuit-breaker logic. | ||
@@ -38,0 +43,0 @@ * @param {Error} err the error to verify. |
{ | ||
"name": "disyuntor", | ||
"description": "A circuit-breaker implementation with exponential backoff.", | ||
"version": "3.3.2", | ||
"version": "3.4.0", | ||
"author": "José F. Romaniello <jfromaniello@gmail.com> (http://joseoncode.com)", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -53,2 +53,6 @@ [![Build Status](https://travis-ci.org/auth0/disyuntor.svg?branch=master)](https://travis-ci.org/auth0/disyuntor) | ||
onClose: (cooldown) => { | ||
console.log(`dns.lookup circuit closed after ${cooldown}ms.`; | ||
} | ||
// //optional callback to prevent some errors to trigger the disyuntor logic | ||
@@ -55,0 +59,0 @@ // //in this case ENOTFOUND is passed to the callback and will |
@@ -149,2 +149,62 @@ const Disyuntor = require('../lib/Disyuntor').Disyuntor; | ||
it('should call onClose after closing in half open state', (done) => { | ||
let closeEvents = []; | ||
protectedFunction = disyuntor({ | ||
name: 'test.func', | ||
timeout: '10ms', | ||
maxFailures: 2, | ||
cooldown: 200, | ||
maxCooldown: 400, | ||
onTrip: (err, failures, cooldown) => tripCalls.push({err, failures, cooldown}), | ||
onClose: (cooldown) => { closeEvents.push({ cooldown}); } | ||
}, function(cb) { | ||
if (error) { | ||
return cb(error); | ||
} | ||
return cb(null, { succeed: true }); | ||
}); | ||
async.series([ | ||
// Open the circuit | ||
cb => { | ||
error = new Error('error-1'); | ||
protectedFunction((err, r) => cb(null, { err, r })) | ||
}, | ||
cb => { | ||
error = new Error('error-2'); | ||
protectedFunction((err, r) => cb(null, { err, r })) | ||
}, | ||
cb => { | ||
error = new Error('error-3'); | ||
protectedFunction((err, r) => cb(null, { err, r })) | ||
}, | ||
// Wait cooldown | ||
cb => setTimeout(cb, 250), | ||
// This should move state from half open to closed | ||
cb => { | ||
error = null; | ||
protectedFunction((err, r) => cb(null, { err, r })) | ||
}, | ||
// Fail again, this should not open the circuit because failures should | ||
// have reset | ||
cb => { | ||
error = new Error('error-4'); | ||
protectedFunction((err, r) => cb(null, { err, r })) | ||
}, | ||
], (err) => { | ||
assert.ifError(err); | ||
assert.equal(closeEvents.length, 1); | ||
assert.deepEqual(closeEvents[0], { cooldown: 200, }); | ||
done(); | ||
}); | ||
}); | ||
it('should backoff on multiple failures', function (done) { | ||
@@ -374,3 +434,3 @@ async.series([ | ||
describe('intermitent failures', function() { | ||
it('should count failures in a row', async function() { | ||
it('should count failures in a row', function() { | ||
const disyuntor = new Disyuntor({ | ||
@@ -382,21 +442,18 @@ name: 'disyuntor test', | ||
//fail | ||
try { | ||
await disyuntor.protect(() => { | ||
return disyuntor.protect(() => { | ||
throw new Error('error 1'); | ||
}).catch(() => { | ||
//works | ||
return disyuntor.protect(() => Promise.resolve(1)); | ||
}).then(() => { | ||
//fail | ||
return disyuntor.protect(() => { | ||
throw new Error('error 1'); | ||
}) | ||
} catch(err){} | ||
}); | ||
}).catch(() => { | ||
disyuntor.protect(() => Promise.resolve(1)); | ||
}); | ||
//works | ||
await disyuntor.protect(async () => 1); | ||
//fails | ||
try { | ||
await disyuntor.protect(() => { | ||
throw new Error('error 1'); | ||
}) | ||
} catch(err){} | ||
await disyuntor.protect(async () => 1); | ||
}); | ||
}); | ||
}); |
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
44294
905
117