<commit_before>import pika
import logging
from structlog import wrap_logger
from app import settings
import time

logger = wrap_logger(logging.getLogger(__name__))


class AsyncConsumer(object):
    """This is an example consumer that will handle unexpected interactions
    with RabbitMQ such as channel and connection closures.

    If RabbitMQ closes the connection, it will reopen it. You should
    look at the output, as there are limited reasons why the connection may
    be closed, which usually are tied to permission related issues or
    socket timeouts.

    If the channel is closed, it will indicate a problem with one of the
    commands that were issued and that should surface in the output as well.

    """
    EXCHANGE = settings.RABBIT_EXCHANGE
    EXCHANGE_TYPE = 'topic'
    DURABLE_QUEUE = True
    QUEUE = settings.RABBIT_QUEUE

    def __init__(self):
        """Create a new instance of the consumer class

        """
        self._connection = None
        self._channel = None
        self._closing = False
        self._consumer_tag = None
        self._url = None
        self._stopped = False

    def connect(self):
        """This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.

        :rtype: pika.SelectConnection

        """
        count = 1
        no_of_servers = len(settings.RABBIT_URLS)

        while not self._stopped:
            server_choice = (count % no_of_servers) - 1
            self._url = settings.RABBIT_URLS[server_choice]

            try:
                logger.info('Connecting to rabbit', attempt=count)
                return pika.SelectConnection(pika.URLParameters(self._url),
                                             self.on_connection_open,
                                             stop_ioloop_on_close=False)
            except pika.exceptions.AMQPConnectionError as e:
                logger.error("Connection error", exception=e)
                count += 1
                logger.error("Connection sleep", no_of_seconds=count)
                time.sleep(count)

                continue

    def close_connection(self):
        """This method closes the connection to RabbitMQ."""
        logger.info('Closing connection')
        self._connection.close()<commit_msg>Updates wording of queue connect log message for consistency<commit_after>import pika
import logging
from structlog import wrap_logger
from app import settings
import time

logger = wrap_logger(logging.getLogger(__name__))


class AsyncConsumer(object):
    """This is an example consumer that will handle unexpected interactions
    with RabbitMQ such as channel and connection closures.

    If RabbitMQ closes the connection, it will reopen it. You should
    look at the output, as there are limited reasons why the connection may
    be closed, which usually are tied to permission related issues or
    socket timeouts.

    If the channel is closed, it will indicate a problem with one of the
    commands that were issued and that should surface in the output as well.

    """
    EXCHANGE = settings.RABBIT_EXCHANGE
    EXCHANGE_TYPE = 'topic'
    DURABLE_QUEUE = True
    QUEUE = settings.RABBIT_QUEUE

    def __init__(self):
        """Create a new instance of the consumer class

        """
        self._connection = None
        self._channel = None
        self._closing = False
        self._consumer_tag = None
        self._url = None
        self._stopped = False

    def connect(self):
        """This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.

        :rtype: pika.SelectConnection

        """
        count = 1
        no_of_servers = len(settings.RABBIT_URLS)

        while not self._stopped:
            server_choice = (count % no_of_servers) - 1
            self._url = settings.RABBIT_URLS[server_choice]

            try:
                logger.info('Connecting to queue', attempt=count)
                return pika.SelectConnection(pika.URLParameters(self._url),
                                             self.on_connection_open,
                                             stop_ioloop_on_close=False)
            except pika.exceptions.AMQPConnectionError as e:
                logger.error("Connection error", exception=e)
                count += 1
                logger.error("Connection sleep", no_of_seconds=count)
                time.sleep(count)

                continue

    def close_connection(self):
        """This method closes the connection to RabbitMQ."""
        logger.info('Closing connection')
        self._connection.close()
{'fraction_non_alphanumeric': 0.06184705390722942, 'fraction_numerical': 0.0012536564981195152, 'mean_word_length': 2.2149093351242444, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3787600', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1157, 'n_words': 415}