<commit_before>var cluster = require('cluster'),
    logfmt  = require('./logfmt'),
    os      = require('os');

module.exports = function() {
  logfmt.log({ evt: 'starting master' });

  for (var i = 0; i < os.cpus().length; i++) {
    cluster.fork();
  }

  cluster.on('disconnect', function(worker) {
    if (!worker.suicide) {
      cluster.fork();
    }
  });

  setupSignalHandlers();
};

function setupSignalHandlers() {
  process.on('SIGINT', function() {
    logfmt.log({ evt: 'received SIGINT, sending myself SIGTERM' });
    process.kill(process.pid, 'SIGTERM');
  });

  process.on('SIGTERM', function() {
    logfmt.log({ evt: 'received SIGTERM, sending myself SIGQUIT' });
    process.kill(process.pid, 'SIGQUIT');
  });

  process.on('SIGQUIT', function() {
    logfmt.log({ evt: 'received SIGQUIT, attempting graceful shutdown' });

    setTimeout(function() {
      logfmt.log({ evt: 'timeout exceeded, forcing shutdown' });

      eachWorker(function(worker) {
        worker.kill();
      });

      process.kill();
    }, 1000).unref();

    cluster.disconnect(function() {
      logfmt.log({ evt: 'all workers disconnected' });
    });
  });
}

function eachWorker(fn) {
  for (var i in cluster.workers) {
    fn(cluster.workers[i]);
  }
}
<commit_msg>log worker disconnects as they occur<commit_after>var cluster = require('cluster'),
    logfmt  = require('./logfmt'),
    os      = require('os');

module.exports = function() {
  logfmt.log({ evt: 'starting master' });

  for (var i = 0; i < os.cpus().length; i++) {
    cluster.fork();
  }

  cluster.on('disconnect', function(worker) {
    logfmt.log({ evt: 'worker (pid ' + worker.process.pid + ') disconnected' });

    if (!worker.suicide) {
      cluster.fork();
    }
  });

  setupSignalHandlers();
};

function setupSignalHandlers() {
  process.on('SIGINT', function() {
    logfmt.log({ evt: 'received SIGINT, sending myself SIGTERM' });
    process.kill(process.pid, 'SIGTERM');
  });

  process.on('SIGTERM', function() {
    logfmt.log({ evt: 'received SIGTERM, sending myself SIGQUIT' });
    process.kill(process.pid, 'SIGQUIT');
  });

  process.on('SIGQUIT', function() {
    logfmt.log({ evt: 'received SIGQUIT, attempting graceful shutdown' });

    setTimeout(function() {
      logfmt.log({ evt: 'timeout exceeded, forcing shutdown' });

      eachWorker(function(worker) {
        worker.kill();
      });

      process.kill();
    }, 1000).unref();

    cluster.disconnect(function() {
      logfmt.log({ evt: 'all workers disconnected' });
    });
  });
}

function eachWorker(fn) {
  for (var i in cluster.workers) {
    fn(cluster.workers[i]);
  }
}

{'fraction_non_alphanumeric': 0.18130418394270637, 'fraction_numerical': 0.003769317753486619, 'mean_word_length': 3.2328548644338118, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2073871', 'n_tokens_mistral': 897, 'n_tokens_neox': 858, 'n_words': 181}