<commit_before>module.exports = Archiver;

var http = require('http');
var os = require('os');
var xtend = require('xtend');

var util = require('./util');
var version = require("../package.json").version;

var HOSTNAME = os.hostname();
var DEFAULTS = {
  skipArchive: false,
  archiveInterval: 60000,
  proxyHost: "results.concurix.com",
  proxyPort: "9090",
  proxyPath: "/results",
}

function Archiver(aggregator, options) {
  if (!(this instanceof Archiver)) return new Archiver(aggregator, options);

  this.aggregator = aggregator;
  this.options = xtend(DEFAULTS, options);
}

Archiver.prototype.start = function start() {
  this.aggregator.reset();
  if (this.interval || this.options.skipArchive) {
    return;
  }
  this.interval = setInterval(this.send.bind(this), this.options.archiveInterval);
}

Archiver.prototype.unref = function unref() {
  if (this.interval && this.interval.unref) {
    this.interval.unref();
  }
}

// This is a stop-gap solution to sending out finalized data.
// At most we will miss the last CLEANUP_INTERVAL millis of data.
Archiver.prototype._checkFinished = function _checkFinished() {
  if (!this.interval) {
    return;
  }
  // If there is more data, don't quit until it is sent.
  if (this.aggregator.windowStart != null && this.interval.ref) {
    this.interval.ref();
  }
}<commit_msg>Add FUDGE to archive interval to prevent floods<commit_after>module.exports = Archiver;

var http = require('http');
var os = require('os');
var xtend = require('xtend');

var util = require('./util');
var version = require("../package.json").version;

var HOSTNAME = os.hostname();
var DEFAULTS = {
  skipArchive: false,
  archiveInterval: 60000,
  proxyHost: "results.concurix.com",
  proxyPort: "9090",
  proxyPath: "/results",
}

// To prevent flood attacks on the proxy when using cluster, fudge interval.
var FUDGE = Math.floor(500 * Math.random())

function Archiver(aggregator, options) {
  if (!(this instanceof Archiver)) return new Archiver(aggregator, options);

  this.aggregator = aggregator;
  this.options = xtend(DEFAULTS, options);
}

Archiver.prototype.start = function start() {
  this.aggregator.reset();
  if (this.interval || this.options.skipArchive) {
    return;
  }
  this.interval = setInterval(this.send.bind(this), this.options.archiveInterval + FUDGE);
}

Archiver.prototype.unref = function unref() {
  if (this.interval && this.interval.unref) {
    this.interval.unref();
  }
}

// This is a stop-gap solution to sending out finalized data.
// At most we will miss the last CLEANUP_INTERVAL millis of data.
Archiver.prototype._checkFinished = function _checkFinished() {
  if (!this.interval) {
    return;
  }
  // If there is more data, don't quit until it is sent.
  if (this.aggregator.windowStart != null && this.interval.ref) {
    this.interval.ref();
  }
}
{'fraction_non_alphanumeric': 0.1394774011299435, 'fraction_numerical': 0.007415254237288136, 'mean_word_length': 4.086175942549372, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '55358', 'n_tokens_mistral': 933, 'n_tokens_neox': 902, 'n_words': 242}