<commit_before>var CircuitBreaker = function(opts) {
  var opts = opts || {};
  this.threshold = opts.threshold || 15;
  this.minErrors = opts.minErrors || 3;
  this.duration = opts.duration || 10000;
  this.numOfBuckets = opts.numOfBuckets || 10;
  this.timeout = opts.timeout || 3000;
  this._buckets = [{ failures: 0, successes: 0, timeouts: 0 }];

  var self = this;

  this._ticker = window.setInterval(function() {
    var bucket = { failures: 0, successes: 0, timeouts: 0 };

    if (self._buckets.length > self.numOfBuckets) {
      self._buckets.shift();
    }

    self._buckets.push(bucket);
  }, this.duration / this.numOfBuckets);
};

CircuitBreaker.prototype.run = function(command, fallback) {
  if (this.isBroken()) {
    if (fallback) {
      fallback();
    }<commit_msg>refactor bucket to use helper method<commit_after>var CircuitBreaker = function(opts) {
  var opts = opts || {};
  this.threshold = opts.threshold || 15;
  this.minErrors = opts.minErrors || 3;
  this.duration = opts.duration || 10000;
  this.numOfBuckets = opts.numOfBuckets || 10;
  this.timeout = opts.timeout || 3000;
  this._buckets = [this._createBucket()];

  var self = this;

  this._ticker = window.setInterval(function() {
    if (self._buckets.length > self.numOfBuckets) {
      self._buckets.shift();
    }

    self._buckets.push(self._createBucket());
  }, this.duration / this.numOfBuckets);
};

CircuitBreaker.prototype._createBucket = function() {
  return { failures: 0, successes: 0, timeouts: 0, shortCircuits: 0 };
};

CircuitBreaker.prototype.run = function(command, fallback) {
  if (this.isBroken()) {
    if (fallback) {
      fallback();
    }
{'fraction_non_alphanumeric': 0.1493975903614458, 'fraction_numerical': 0.02289156626506024, 'mean_word_length': 3.5631868131868134, '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': '464119', 'n_tokens_mistral': 615, 'n_tokens_neox': 543, 'n_words': 115}