How to use the opossum function in opossum

To help you get started, we’ve selected a few opossum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodeshift / opossum / examples / react / client / src / App.js View on Github external
constructor () {
    super();

    // state
    this.state = { requestState: [] };

    // binds
    this.makeRequest = this.makeRequest.bind(this);
    this.makeNode = this.makeNode.bind(this);
    this.clearNodes = this.clearNodes.bind(this);

    // circuit breaker settings
    this.circuitBreakerOptions = { timeout: 500, maxFailures: 3, resetTimeout: 5000 };
    this.route = 'http://localhost:3000/flakeyService';

    this.circuit = circuitBreaker(() => $.get(this.route), this.circuitBreakerOptions);

    // circuit breaker events
    this.circuit.fallback(() =>
      ({ body: `${this.route} unavailable right now. Try later.` }));
    this.circuit.on('success', (result) =>
      this.makeNode({ state: `SUCCESS`, body: `${JSON.stringify(result)}` }));
    this.circuit.on('timeout', () =>
      this.makeNode({ state: `TIMEOUT`, body: `${this.route} is taking too long to respond.` }));
    this.circuit.on('reject', () =>
      this.makeNode({ state: `REJECTED`, body: `The breaker for ${this.route} is open. Failing fast.` }));
    this.circuit.on('open', () =>
      this.makeNode({ state: `OPEN`, body: `The breaker for ${this.route} just opened.` }));
    this.circuit.on('halfOpen', () =>
      this.makeNode({ state: `HALF_OPEN`, body: `The breaker for ${this.route} is half open.` }));
    this.circuit.on('close', () =>
      this.makeNode({ state: `CLOSE`, body: `The breaker for ${this.route} has closed. Service OK.` }));
github bbc / simorgh / src / app / lib / utilities / fetchCircuitBreaker / index.js View on Github external
return (url, options) => {
    const { host } = new URL(url);
    let circuitBreaker = circuitBreakers[host];

    if (!circuitBreaker) {
      const circuitBreakerOptions = {
        name: host,
        timeout: 5000,
        resetTimeout: 10000,
      };
      circuitBreakers[host] = new CircuitBreaker(fetch, circuitBreakerOptions);
      circuitBreaker = circuitBreakers[host];
    }

    return !options
      ? circuitBreaker.fire(url)
      : circuitBreaker.fire(url, options);
  };
}

opossum

A fail-fast circuit breaker for promises and callbacks

Apache-2.0
Latest version published 8 days ago

Package Health Score

92 / 100
Full package analysis

Popular opossum functions