• This repository has been archived on 12/Dec/2020
  • Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hystrix-like circuit breaker for JavaScript.

CircuitBreaker Build Status

Hystrix-like circuit breaker for JavaScript.

Usage

var breaker = new CircuitBreaker();

var command = function(success, failed) {
  restCall()
    .done(success)
    .fail(failed);
};

var fallback = function() {
  alert("Service is down");
};

breaker.run(command, fallback);

API

CircuitBreaker([config])

Create a new instance of a circuit breaker. Accepts the following config options:

windowDuration

Duration of statistical rolling window in milliseconds. This is how long metrics are kept for the circuit breaker to use and for publishing.

The window is broken into buckets and "roll" by those increments.

Default Value: 10000

numBuckets

Number of buckets the rolling statistical window is broken into.

Default Value: 10

timeoutDuration

Time in milliseconds after which a command will timeout.

Default Value: 3000

errorThreshold

Error percentage at which the circuit should trip open and start short-circuiting requests to fallback logic.

Default Value: 50

volumeThreshold

Minimum number of requests in rolling window needed before tripping the circuit will occur.

For example, if the value is 20, then if only 19 requests are received in the rolling window (say 10 seconds) the circuit will not trip open even if all 19 failed.

Default Value: 5

onCircuitOpen(metrics)

Function that is run whenever the circuit is opened (i.e. the threshold is reached). Receives the metrics for the current window as an argument.

Default Value: no-op

onCircuitClose(metrics)

Function that is run whenever the circuit is closed (i.e. the service is back up). Receives the metrics for the current window as an argument.

Default Value: no-op

run(command, [fallback])

Runs a command if circuit is closed, otherwise defaults to a fallback if provided. The command is called with success and failure handlers which you need to call at the appropriate point in your command. For example, if an ajax request succeeds the the success function should be called to notify the breaker. If neither success or failed are called then the command it's assumed the command timed out.

isOpen

Checks whether the breaker is currently accepting requests.

forceOpen

Forces the circuit to open.

Metrics will not be collected while the circuit is forced.

forceClose

Forces the circuit to close.

Metrics will not be collected while the circuit is forced.

unforce

Returns the circuit to its last unforced state.

Contributing

Install the dependencies

npm install

Run the tests with:

grunt test

or

grunt test:browser

More Repositories

1

circuitbox

Circuit breaker built with large Ruby apps in mind.
Ruby
702
star
2

tenacity

Dropwizard + Hystrix Module.
Java
203
star
3

model_attribute

ModelAttribute gem - attributes for non-ActiveRecord models
Ruby
126
star
4

YMSwipeTableViewCell

YMSwipeTableViewCell is a lightweight library that enables table view cell swiping.
Objective-C
110
star
5

breakerbox

Frontend for Tenacity + Archaius
Java
63
star
6

yam

The official Yammer Ruby gem..
Ruby
45
star
7

dropwizard-auth-ldap

Dropwizard Authentication Module for LDAP using JNDI.
Java
36
star
8

sched.do

Ruby
30
star
9

yam-python

A python wrapper around the Yammer API.
Python
29
star
10

telemetry

A dapper-like substance in Java.
Java
18
star
11

schedulizer

An app to manage schedules
JavaScript
15
star
12

dropwizard-testing-integration

Utilities for writing dropwizard integration tests.
Java
15
star
13

EspressoApplicationSample-

EspressoApplicationSample
Java
14
star
14

dotnet-yammersdk

dotnet-yammersdk - build windows universal apps using the yammer fabric
C#
10
star
15

ios-oauth-demo

A sample application to demonstrate how the Yammer OAuth API works.
Objective-C
9
star
16

ios-yammer-sdk

Yammer iOS SDK
Objective-C
8
star
17

backbone-component

A thin layer on top of Backbone's view class to add nested child views.
JavaScript
7
star
18

windows-phone-oauth-sdk-demo

SDK tools and a demo for Windows Phone users to consume the Yammer API via Oauth.
C#
7
star
19

JS_SDK_Sample

6
star
20

yammer-collections

Collections utilities which build on top of Guava and the standard collections library.
Java
6
star
21

docker-registry-cache

Shell
5
star
22

backups

Backups as a Service
Java
4
star
23

mcrouter-build-docker

An Ubuntu 12.04 package builder for mcrouter
Makefile
4
star
24

powershell_example

A Powershell example of using the Yammer Oauth 2 to retrieve a token
PowerShell
3
star
25

azure-table

Azure Table backed Guava Table implementation.
Java
3
star
26

yamoverflow

YamOverflow.
Ruby
3
star