ace-circuit-breaker
v0.90.0
Published
Javascript circuit breaker
Downloads
425
Readme
Ace Circuit Breaker
A simple circuit breaker implementation for javascript
Usage
let breaker = new CircuitBreaker();
const command = (success, failure)=> {
...
response.then((data)=> {
...
...
success();
})
.catch((err)=> {
...
failure();
});
};
const fallback = ()=> {
...
console.log('fallback called...');
...
...
}
breaker.run(command, fallback);
Options
{
timeWindow: 10000,
failureThreshold: 50,
minThreshold: 3,
resetTime: 3000,
}
timeWindow
The duration of time, in miliseconds, that the circuit breaker uses to determine if the error ratio trips the breaker open (defaults to 10,000)
failureThreshold
The ratio of errors to total number of calls (defaults to 50 = 50%)
minThreshold
The minimum number of calls to .run before the ratio can trigger the breaker to open. (defaults to 3) e.g. if the total amount of calls is 2 the breaker will still not open even if both calls failed
resetTime
The time in miliseconds before the circuit breaker becomes "half-open" and will allow the next call to breaker.run to execute the command If the command fails then the breaker will OPEN and wait for another reset interval to be "half-open" and allow single command to execute If the command succeeds then the breaker will reset the breaker will be back to CLOSED normal operation
Install
npm install ace-circuit-breaker
RoadMap
- Add command timeout