lib/kju.js
function KJU(configuration) {
  var self = this
    , option;

  // defaults
  this.limit = 500;
  this.ms = 100;
  this.interval = 15000;
  this.warnings = true;
  this.enabled = true;
  this.recover = true;
  this.dump = true;
  this.path = process.cwd() + '/';
  this.name = 'node_kju_backup.{sequence}.kju';

  // apply the configuration
  for (option in configuration)
    this[option] = configuration[option];

  // these values should not be configured
  this.buffer = [];
  this.length = 0;

  this.drained = 0;
  this.processed = 0;
  this.since = Date.now();

  this.minimum = this.interval / 2;
  this.maximum = this.interval * 2;

  // initialize the event emitter
  EventEmitter2.call(this, { wildcard: true });

  if (this.recover) this.recovery();
  if (this.enabled) this.enable();

  // make sure our backup path exists
  fsExists(this.path, function existing(exists) {
    if (!exists) {
      return self.emit('error', new Error(self.path + ' does not exist.'));
    }

    if (self.path[self.path.length - 1] !== '/') {
      return self.emit('error', new Error(self.path + ' should end with a slash'));
    }
  });
}
function KJU(configuration) {
  var self = this
    , option;

  // defaults
  this.limit = 500;
  this.ms = 100;
  this.interval = 15000;
  this.warnings = true;
  this.enabled = true;
  this.recover = true;
  this.dump = true;
  this.path = process.cwd() + '/';
  this.name = 'node_kju_backup.{sequence}.kju';

  // apply the configuration
  for (option in configuration)
    this[option] = configuration[option];

  // these values should not be configured
  this.buffer = [];
  this.length = 0;

  this.drained = 0;
  this.processed = 0;
  this.since = Date.now();

  this.minimum = this.interval / 2;
  this.maximum = this.interval * 2;

  // initialize the event emitter
  EventEmitter2.call(this, { wildcard: true });

  if (this.recover) this.recovery();
  if (this.enabled) this.enable();

  // make sure our backup path exists
  fsExists(this.path, function existing(exists) {
    if (!exists) {
      return self.emit('error', new Error(self.path + ' does not exist.'));
    }

    if (self.path[self.path.length - 1] !== '/') {
      return self.emit('error', new Error(self.path + ' should end with a slash'));
    }
  });
}
function KJU ( configuration ) { var self = this , option ; // defaults this . limit = 500 ; this . ms = 100 ; this . interval = 15000 ; this . warnings = true ; this . enabled = true ; this . recover = true ; this . dump = true ; this . path = process . cwd ( ) + '/' ; this . name = 'node_kju_backup.{sequence}.kju' ; // apply the configuration for ( option in configuration ) this [ option ] = configuration [ option ] ; // these values should not be configured this . buffer = [ ] ; this . length = 0 ; this . drained = 0 ; this . processed = 0 ; this . since = Date . now ( ) ; this . minimum = this . interval / 2 ; this . maximum = this . interval * 2 ; // initialize the event emitter EventEmitter2 . call ( this , { wildcard : true } ) ; if ( this . recover ) this . recovery ( ) ; if ( this . enabled ) this . enable ( ) ; // make sure our backup path exists fsExists ( this . path , function existing ( exists ) { if ( ! exists ) { return self . emit ( 'error' , new Error ( self . path + ' does not exist.' ) ) ; } if ( self . path [ self . path . length - 1 ] !== '/' ) { return self . emit ( 'error' , new Error ( self . path + ' should end with a slash' ) ) ; } } ) ; }
Initialize our queue.

Options:

- `limit` Limit of the buffer. Defaults to 500 items.
- `ms` Amount of milliseconds to increase or decrease the interval. Defaults
to 100 ms
- `interval` Baseline interval for queue, this is where the minimum and
maximum levels are based off.  Defaults to 15000 ms
- `warnings` When enabled we will emit events when our maximum or minimum
interval has been reached. Defaults to true.
- `enabled` Enable the queue by default. Defaults to true.
- `recover` Enable recovery of old `.kju` storage files so no data is lost
when the process is exiting. Defaults to true.
- `dump` In addition to the storage of `.kju` files also dump JSON to
stderr. Defaults to false.
- `path` Location where the `.kju` recover files are stored. Defaults to
the current working directory.
- `name` Name of the `.kju` recover files.

@constructor
@param {Object} configuration kju configuration
@api public
Initialize our queue .