<commit_before>/**
 * A worker will listen for jobs on the job queue, and execute them.
 */
var async = require('async');

function bootstrapWorker (api, config, next) {

  var follower = function (cb) {
    api.messaging.listen('seguir-publish-to-followers', function (data, next) {
      api.feed.insertFollowersTimeline(data, next);
    }, cb);
  };

  var mentions = function (cb) {
    api.messaging.listen('seguir-publish-mentioned', function (data, cb) {
      api.feed.insertMentionedTimeline(data, cb);
    }, cb);
  };

  async.series([
    follower,
    mentions
  ], function () {
    console.log('Seguir worker ready for work ...');
    return next && next();
  });

}

/* istanbul ignore if */
if (require.main === module) {
  var config = require('../config')();
  require('../../api')(config, function (err, api) {
    if (err) { return process.exit(0); }
    bootstrapWorker(api, config);
  });
} else {
  // Used for testing<commit_msg>Add logging to worker process, keep consistent with server logging via bunyan<commit_after>/**
 * A worker will listen for jobs on the job queue, and execute them.
 */
var async = require('async');
var restify = require('restify');
var bunyan = require('bunyan');
var logger = bunyan.createLogger({
  name: 'seguir',
  serializers: restify.bunyan.serializers
});

function bootstrapWorker (api, config, next) {

  var follower = function (cb) {
    api.messaging.listen('seguir-publish-to-followers', function (data, next) {
      logger.debug('Processing publish-to-followers message', data);
      api.feed.insertFollowersTimeline(data, next);
    }, cb);
  };

  var mentions = function (cb) {
    api.messaging.listen('seguir-publish-mentioned', function (data, cb) {
      logger.debug('Processing publish-mentioned message', data);
      api.feed.insertMentionedTimeline(data, cb);
    }, cb);
  };

  async.series([
    follower,
    mentions
  ], function () {
    console.log('Seguir worker ready for work ...');
    return next && next();
  });

}

/* istanbul ignore if */
if (require.main === module) {
  var config = require('../config')();
  require('../../api')(config, function (err, api) {
    if (err) { return process.exit(0); }
    bootstrapWorker(api, config);
  });
} else {
  // Used for testing
{'fraction_non_alphanumeric': 0.16285211267605634, 'fraction_numerical': 0.0008802816901408451, 'mean_word_length': 3.3795761078998074, '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': '5029719', 'n_tokens_mistral': 733, 'n_tokens_neox': 704, 'n_words': 189}