<commit_before>// Copyright 2013 The Obvious Corporation.

/**
 * @fileoverview Store that writes messages to disk in batches, useful for dev
 * environments and testing, or for draining a queue to a local file.  Messages
 * will be acknowledged when the write has been confirmed.
 *
 * Also used as a base class for other implementations.
 */

var fs = require('fs')
var path = require('path')
var logg = require('logg')
var moment = require('moment')


/**
 * @param {SqsSink} sink
 * @param {string} outDir Location to store messages
 * @param {string} filenamePattern momentjs compatible string for generating filenames
 * @param {number} flushFreqSec How often to flush messages
 */
function MessageStore(sink, outDir, filenamePattern, flushFreqSec) {

  this._outDir = outDir
  this._filenamePattern = filenamePattern.replace(/PID/, process.pid)
  this._flushFreqSec = flushFreqSec || 60
  this._pendingMessages = {}
  this._flushTimer = null

  this.sink = sink
  this.sink.on('receive', this.handleMessages.bind(this))

  this.logger.info('Writing messages in', this._flushFreqSec, 'second batches')
}
module.exports = MessageStore


/**
 * Alias of typical set timeout, used for testing.
 * @type {Function}
 */
MessageStore.setTimeout = setTimeout


/**
 * Alias of typical node's FS library, used for testing.<commit_msg>Add HOSTNAME field to logname format<commit_after>// Copyright 2013 The Obvious Corporation.

/**
 * @fileoverview Store that writes messages to disk in batches, useful for dev
 * environments and testing, or for draining a queue to a local file.  Messages
 * will be acknowledged when the write has been confirmed.
 *
 * Also used as a base class for other implementations.
 */

var fs = require('fs')
var logg = require('logg')
var moment = require('moment')
var os = require('os')
var path = require('path')

/**
 * @param {SqsSink} sink
 * @param {string} outDir Location to store messages
 * @param {string} filenamePattern momentjs compatible string for generating filenames
 * @param {number} flushFreqSec How often to flush messages
 */
function MessageStore(sink, outDir, filenamePattern, flushFreqSec) {

  this._outDir = outDir
  this._filenamePattern = filenamePattern.replace(/PID/, process.pid).replace(/HOSTNAME/, os.hostname())
  this._flushFreqSec = flushFreqSec || 60
  this._pendingMessages = {}
  this._flushTimer = null

  this.sink = sink
  this.sink.on('receive', this.handleMessages.bind(this))

  this.logger.info('Writing messages in', this._flushFreqSec, 'second batches')
}
module.exports = MessageStore


/**
 * Alias of typical set timeout, used for testing.
 * @type {Function}
 */
MessageStore.setTimeout = setTimeout


/**
 * Alias of typical node's FS library, used for testing.
{'fraction_non_alphanumeric': 0.10568513119533528, 'fraction_numerical': 0.004373177842565598, 'mean_word_length': 4.382352941176471, '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': '7107176', 'n_tokens_mistral': 806, 'n_tokens_neox': 765, 'n_words': 282}