<commit_before>'use strict';

// Simple auto-reclosing circuit breaker for Node-style calls, inspired by the
// Akka breaker. The circuit breaker helps protect functions that sometimes
// fail and avoid failure cascades in a graph of function calls. The breaker
// API was inspired by the Akka breaker with a few refinements to make it
// simpler and more in line with the usual Node function call patterns.

const _ = require('underscore');
const perf = require('abacus-perf');
const yieldable = require('abacus-yieldable');
const util = require('util');

const last = _.last;
const initial = _.initial;
const extend = _.extend;
const isFunction = _.isFunction;
const map = _.map;
const object = _.object;
const pairs = _.pairs;
const functions = _.functions;
const bind = _.bind;

// Setup debug log
const debug = require('abacus-debug')('abacus-breaker');

// Circuit breaker options, with the following defaults:
// timeout a call after 10 secs,
// 20 calls must occur in 10 secs before stats matter,
// trip circuit when 50% calls are failures or latent,
// sleep 5 secs before trying again a tripped circuit
const options = (callTimeout, callThreshold, errorPercentage, resetTimeout) => {
  return {
    timeout: callTimeout || 5000,
    threshold: callThreshold || 10,
    errors: errorPercentage || 50,
    reset: resetTimeout || 5000
  };
};

// An error used to report a timeout
const TimeoutError = function(name, timeout) {
  Error.captureStackTrace(this);
  this.message = util.format(
    'Function %s timed out after %d ms', name, timeout);
};
TimeoutError.prototype = Error.prototype;

// An error used to report a circuit breaker fast-fail<commit_msg>Increase default circuit breaker call timeout from 5 secs to 20 secs<commit_after>'use strict';

// Simple auto-reclosing circuit breaker for Node-style calls, inspired by the
// Akka breaker. The circuit breaker helps protect functions that sometimes
// fail and avoid failure cascades in a graph of function calls. The breaker
// API was inspired by the Akka breaker with a few refinements to make it
// simpler and more in line with the usual Node function call patterns.

const _ = require('underscore');
const perf = require('abacus-perf');
const yieldable = require('abacus-yieldable');
const util = require('util');

const last = _.last;
const initial = _.initial;
const extend = _.extend;
const isFunction = _.isFunction;
const map = _.map;
const object = _.object;
const pairs = _.pairs;
const functions = _.functions;
const bind = _.bind;

// Setup debug log
const debug = require('abacus-debug')('abacus-breaker');

// Circuit breaker options, with the following defaults:
// timeout a call after 20 secs,
// 10 calls must occur in 10 secs before stats matter,
// trip circuit when 50% calls are failures or latent,
// sleep 5 secs before trying again a tripped circuit
const options = (callTimeout, callThreshold, errorPercentage, resetTimeout) => {
  return {
    timeout: callTimeout || 20000,
    threshold: callThreshold || 10,
    errors: errorPercentage || 50,
    reset: resetTimeout || 5000
  };
};

// An error used to report a timeout
const TimeoutError = function(name, timeout) {
  Error.captureStackTrace(this);
  this.message = util.format(
    'Function %s timed out after %d ms', name, timeout);
};
TimeoutError.prototype = Error.prototype;

// An error used to report a circuit breaker fast-fail
{'fraction_non_alphanumeric': 0.09787735849056604, 'fraction_numerical': 0.013561320754716982, 'mean_word_length': 4.109939759036145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6250099', 'n_tokens_mistral': 979, 'n_tokens_neox': 914, 'n_words': 408}