src/server/graceful.js
function Graceful(options) {
  /*jshint maxcomplexity: 9 */

  options = options || {};

  this.shuttingDown = false;

  this._checks = [];
  this._sending = false;

  this.pollInterval = options.pollInterval || 250;
  localUtil.verifyType('number', this, 'pollInterval');

  this.timeout = options.timeout || 5 * 1000;
  localUtil.verifyType('number', this, 'timeout');

  this.messenger = options.messenger || require('thehelp-last-ditch');
  localUtil.verifyType('function', this, 'messenger');

  this.log = options.log || logShim('thehelp-cluster:graceful');
  localUtil.verifyLog(this.log);

  var _this = this;
  this.addCheck(function areWeSending() {
    return _this._sending === false;
  });

  this._process = options._process || process;
  this._cluster = options._cluster || cluster;
  this._logPrefix = localUtil.getLogPrefix();
  this._setupListeners();

  if (Graceful.instance) {
    this.log.warn('More than one Graceful instance created in this process. ' +
      'There are now duplicate process-level wireups!');
  }
  Graceful.instance = this;
}
function Graceful(options) {
  /*jshint maxcomplexity: 9 */

  options = options || {};

  this.shuttingDown = false;

  this._checks = [];
  this._sending = false;

  this.pollInterval = options.pollInterval || 250;
  localUtil.verifyType('number', this, 'pollInterval');

  this.timeout = options.timeout || 5 * 1000;
  localUtil.verifyType('number', this, 'timeout');

  this.messenger = options.messenger || require('thehelp-last-ditch');
  localUtil.verifyType('function', this, 'messenger');

  this.log = options.log || logShim('thehelp-cluster:graceful');
  localUtil.verifyLog(this.log);

  var _this = this;
  this.addCheck(function areWeSending() {
    return _this._sending === false;
  });

  this._process = options._process || process;
  this._cluster = options._cluster || cluster;
  this._logPrefix = localUtil.getLogPrefix();
  this._setupListeners();

  if (Graceful.instance) {
    this.log.warn('More than one Graceful instance created in this process. ' +
      'There are now duplicate process-level wireups!');
  }
  Graceful.instance = this;
}
/*
The `constructor` has no required parameters. Optional parameters:

+ `pollInterval` - how often to attempt to take down process by first checking all
registered 'ready to stop process' check functions
+ `timeout` - how long to wait for the 'ready to stop process' checks before taking the
process down forcefully
+ `messenger` - a `function(err, options, cb)` that gets the information supplied to the
`shutdown()` method. Defaults to `thehelp-last-ditch`.
+ `log` - a logger object: `info`, `warn` and `error` keys with the signature
`function(string)`. By default, whatever `thehelp-log-shim` gives us.

_Note: it's recommended to create an instance of this class just once per process, since
it listens for a number of process-level events. See `_setupListeners()` below._