'use strict';

const logPayload = require('./util/logging-util').formattedPayload;


/**
 * @param  {Object} message_queue      message_queue
 * @param  {Object} message_processing message_processing
 * @param  {Bunyan} logger             logger
 * @return {Object}                    methods
 */
exports.create = function(message_queue, message_processing, logger) {
  return {
    receiveMessageBatch: receiveMessageBatch,
  };


  /**
   * Recursive call to receive and process messages infinitely.
   * @type {Function}
   * @param {String} queue_name Name of queue to capture messages from.
   * @param {Function} callback Invoked with [err].
   */
  function receiveMessageBatch(queue_name, callback) {
    message_queue.receiveQueueMessages(queue_name, (err, sqs_messages) => {
      if (err) {
        err.payload = {
          queue: queue_name,
        };
        logger.trace(err, 'Error receiving messages for SQS queue');
        callback(err);
        return;
      }

      const message_count = sqs_messages.length;

      // Receive next batch immediately
      if (!message_count) {
        callback();
        return;
      }

      logger.info(logPayload({
        queue: queue_name,
        count: message_count,
      }), 'Message batch received');

      message_processing.processMessages(sqs_messages, queue_name, () => {
        logger.info(logPayload({
          queue: queue_name,
          count: message_count,
        }), 'Done processing message batch');
        callback();
      });
    });
  }
};

@@ -698,24 +698,59 @@
 callback) %7B%0A
+    const start_time = Date.now();%0A
     message_
@@ -1170,24 +1170,87 @@
 n;%0A      %7D%0A%0A
+      const receive_duration_millis = Date.now() - start_time;%0A
       logger
@@ -1321,24 +1321,82 @@
 sage_count,%0A
+        duration_seconds: receive_duration_millis / 1000,%0A
       %7D), 'M
@@ -1492,24 +1492,92 @@
 me, () =%3E %7B%0A
+        const processing_duration_millis = Date.now() - start_time;%0A
         logg
@@ -1650,32 +1650,95 @@
  message_count,%0A
+          duration_seconds: processing_duration_millis / 1000,%0A
         %7D), 'Don

Add logging of processing time