<commit_before>var _ = require('underscore');

module.exports = (function() {

  var HOME_DIR = '/web';

  /**
   * @param {Object} pulsar
   * @constructor
   */
  function PulsarREST(pulsar) {
    this.pulsar = pulsar;
  }

  /**
   * @param {Object} server
   */
  PulsarREST.prototype.installHandlers = function(server) {
    var self = this;
    this.protocol = server.secure ? 'https' : 'http';

    server.post('/:app/:env', function(req, res, next) {
      var wait = !!req.params.wait;
      self.pulsar.createTask(req.params, function(err, task) {
        next.ifError(err);
        var response = {
          id: task.id,
          url: self.protocol + '://' + req.headers.host + HOME_DIR + '/task/' + task.id
        };
        task.execute();
        if (wait) {
          task.on('close', function() {
            response.data = task.getData();
            res.send(response);
            next();
          });
        } else {
          res.send(response);
          next();
        }
      });
    });

    server.get('/task/:id', function(req, res, next) {
      self.pulsar.getTask(req.params.id, function(err, task) {
        next.ifError(err);
        res.send(task.getData());
        next();
      });
    });

    server.post('/task/:id/kill', function(req, res, next) {
      self.pulsar.getTask(req.params.id, function(err, task) {
        next.ifError(err);
        task.kill();
        res.send(200);
        next();
      });
    });

    server.get('/tasks', function(req, res, next) {
      self.pulsar.getTaskList(function(err, taskList) {
        taskList = _.map(taskList, function(task) {
          return task.getData();<commit_msg>Replace next.ifError with an old-school error handling.<commit_after>var _ = require('underscore');

module.exports = (function() {

  var HOME_DIR = '/web';

  /**
   * @param {Object} pulsar
   * @constructor
   */
  function PulsarREST(pulsar) {
    this.pulsar = pulsar;
  }

  /**
   * @param {Object} server
   */
  PulsarREST.prototype.installHandlers = function(server) {
    var self = this;
    this.protocol = server.secure ? 'https' : 'http';

    server.post('/:app/:env', function(req, res, next) {
      var wait = !!req.params.wait;
      self.pulsar.createTask(req.params, function(err, task) {
        next.ifError(err);
        var response = {
          id: task.id,
          url: self.protocol + '://' + req.headers.host + HOME_DIR + '/task/' + task.id
        };
        task.execute();
        if (wait) {
          task.on('close', function() {
            response.data = task.getData();
            res.send(response);
            next();
          });
        } else {
          res.send(response);
          next();
        }
      });
    });

    server.get('/task/:id', function(req, res, next) {
      self.pulsar.getTask(req.params.id, function(err, task) {
        if (err) {
          return next(err);
        }
        res.send(task.getData());
        next();
      });
    });

    server.post('/task/:id/kill', function(req, res, next) {
      self.pulsar.getTask(req.params.id, function(err, task) {
        if (err) {
          return next(err);
        }
        task.kill();
        res.send(200);
        next();
      });
    });

    server.get('/tasks', function(req, res, next) {
      self.pulsar.getTaskList(function(err, taskList) {
        if (err) {
          return next(err);
        }
        taskList = _.map(taskList, function(task) {
          return task.getData();
{'fraction_non_alphanumeric': 0.1693848354792561, 'fraction_numerical': 0.0017167381974248926, 'mean_word_length': 1.9181969949916529, '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': '2051587', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1126, 'n_words': 199}