<commit_before>import json
import logging
import os

from handlers import config

from mozillapulse.config import PulseConfiguration
from mozillapulse.consumers import GenericConsumer


logging.basicConfig(format='%(asctime)s %(levelname)s:\t %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S')
LOG = logging.getLogger()


class PulseConsumer(GenericConsumer):
    """
    Creates a consumer object for the given exchange.

    Documentation for the exchanges:
    https://wiki.mozilla.org/Auto-tools/Projects/Pulse/Exchanges
    """

    def __init__(self, exchange, **kwargs):
        super(PulseConsumer, self).__init__(
            PulseConfiguration(**kwargs), exchange, **kwargs)


def run_pulse(exchange, topic, event_handler, dry_run=True):
    """Listen to a pulse exchange in a infinite loop. Call event_handler on every message."""

    label = 'pulse_actions'
    user = os.environ.get('PULSE_USER')
    password = os.environ.get('PULSE_PW')
    pulse_args = {
        'applabel': label,
        'topic': topic,
        'durable': False,
        'user': user,
        'password': password
    }

    # Pulse consumer's callback passes only data and message arguments
    # to the function, we need to pass dry-run
    def handler_with_dry_run(data, message):
        return event_handler(data, message, dry_run)

    pulse = PulseConsumer(exchange, callback=handler_with_dry_run, **pulse_args)
    LOG.info('Listening on %s, with topic %s' % (exchange, topic))

    while True:
        pulse.listen()


def main():

    current_dir = os.path.dirname(os.path.abspath(__file__))
    config_path = os.path.join(current_dir, 'run_time_config.json')<commit_msg>Made queues durable<commit_after>import json
import logging
import os

from handlers import config

from mozillapulse.config import PulseConfiguration
from mozillapulse.consumers import GenericConsumer


logging.basicConfig(format='%(asctime)s %(levelname)s:\t %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S')
LOG = logging.getLogger()


class PulseConsumer(GenericConsumer):
    """
    Creates a consumer object for the given exchange.

    Documentation for the exchanges:
    https://wiki.mozilla.org/Auto-tools/Projects/Pulse/Exchanges
    """

    def __init__(self, exchange, **kwargs):
        super(PulseConsumer, self).__init__(
            PulseConfiguration(**kwargs), exchange, **kwargs)


def run_pulse(exchange, topic, event_handler, dry_run=True):
    """Listen to a pulse exchange in a infinite loop. Call event_handler on every message."""

    label = 'pulse_actions'
    user = os.environ.get('PULSE_USER')
    password = <PASSWORD>('P<PASSWORD>')
    pulse_args = {
        'applabel': label,
        'topic': topic,
        'durable': True,
        'user': user,
        'password': password
    }

    # Pulse consumer's callback passes only data and message arguments
    # to the function, we need to pass dry-run
    def handler_with_dry_run(data, message):
        return event_handler(data, message, dry_run)

    pulse = PulseConsumer(exchange, callback=handler_with_dry_run, **pulse_args)
    LOG.info('Listening on %s, with topic %s' % (exchange, topic))

    while True:
        pulse.listen()


def main():

    current_dir = os.path.dirname(os.path.abspath(__file__))
    config_path = os.path.join(current_dir, 'run_time_config.json')
{'fraction_non_alphanumeric': 0.11600237953599048, 'fraction_numerical': 0.0, 'mean_word_length': 3.5140939597315435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3590353', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1003, 'n_words': 263}