<commit_before>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
'use strict';

var debug = require('debug')('Example:Mail:Queue');
var contact = require('../../configs').create().get('contact');
var amqp = require('amqplib');
var mailer = require('./mailer');

function sendMail (input, callback) {
  var open = amqp.connect(contact.queue.url());

  open.then(function (conn) {
    debug('AMQP connection open');

    return conn.createChannel().then(function (ch) {
      debug('AMQP channel created');

      var q = contact.queue.name();

      return ch.assertQueue(q).then(function () {
        ch.sendToQueue(q, new Buffer(JSON.stringify(input)));
        debug('AMQP message sent', input);
      });
    });
  })
  .then(callback, function (err) {
    debug('AMQP message failure', err);
    callback(err);
  });
}

function contactWorker () {
  amqp.connect(contact.queue.url()).then(function (conn) {
    process.once('SIGINT', function () {
      conn.close();
    });

    return conn.createChannel().then(function (ch) {
      var q = contact.queue.name();
      
      ch.assertQueue(q).then(function () {
        ch.consume(q, function (msg) {
          if (msg !== null) {
            mailer.send(JSON.parse(msg.content.toString()), function(err) {
              if (err) {<commit_msg>update contactWorker to return promise from assertQueue<commit_after>/**
 * Copyright (c) 2015 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
'use strict';

var debug = require('debug')('Example:Mail:Queue');
var contact = require('../../configs').create().get('contact');
var amqp = require('amqplib');
var mailer = require('./mailer');

function sendMail (input, callback) {
  var open = amqp.connect(contact.queue.url());

  open.then(function (conn) {
    debug('AMQP connection open');

    return conn.createChannel().then(function (ch) {
      debug('AMQP channel created');

      var q = contact.queue.name();

      return ch.assertQueue(q).then(function () {
        ch.sendToQueue(q, new Buffer(JSON.stringify(input)));
        debug('AMQP message sent', input);
      });
    });
  })
  .then(callback, function (err) {
    debug('AMQP message failure', err);
    callback(err);
  });
}

/**
 * This is the main proc of the contact worker process.
 */
function contactWorker () {
  amqp.connect(contact.queue.url()).then(function (conn) {
    process.once('SIGINT', function () {
      conn.close();
    });

    return conn.createChannel().then(function (ch) {
      var q = contact.queue.name();
      
      return ch.assertQueue(q).then(function () {
        ch.consume(q, function (msg) {
          if (msg !== null) {
            mailer.send(JSON.parse(msg.content.toString()), function(err) {
              if (err) {
{'fraction_non_alphanumeric': 0.16751961787785738, 'fraction_numerical': 0.002729443875810304, 'mean_word_length': 3.164772727272727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3588521', 'n_tokens_mistral': 891, 'n_tokens_neox': 864, 'n_words': 211}