<commit_before>from redis import Redis
from rq import Queue


class RqWorkerQueue(object):

    '''
    A reference to a `rq` worker queue.

    Configuration:
        `RQ_WORKER_NAME`: Name of the `rq` worker.
    '''

    __EXT_NAME = 'rq-worker-queue'

    def __init__(self, app=None):
        self.__app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        self.__app = app
        self.__app.config.setdefault('RQ_WORKER_NAME', 'default')

        if not hasattr(self.__app, 'extensions'):
            self.__app.extensions = {}

        queue_name = self.__app.config['RQ_WORKER_NAME']
        queue = Queue(name=queue_name, connection=Redis(), default_timeout=3600)
        self.__app.extensions[self.__EXT_NAME] = queue

    def enqueue(self, *nargs, **kwargs):
        queue = self.__app.extensions[self.__EXT_NAME]
        return queue.enqueue(*nargs, **kwargs)


rq_worker_queue = RqWorkerQueue()<commit_msg>dont use hasattr for checking presence of attrs<commit_after>from redis import Redis
from rq import Queue


class RqWorkerQueue(object):

    '''
    A reference to a `rq` worker queue.

    Configuration:
        `RQ_WORKER_NAME`: Name of the `rq` worker.
    '''

    __EXT_NAME = 'rq-worker-queue'

    def __init__(self, app=None):
        self.__app = app
        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        self.__app = app
        self.__app.config.setdefault('RQ_WORKER_NAME', 'default')

        try:
            # check for presence of existing extension dict
            self.__app.extensions
        except AttributeError:
            self.__app.extensions = {}

        queue_name = self.__app.config['RQ_WORKER_NAME']
        queue = Queue(name=queue_name, connection=Redis(), default_timeout=3600)
        self.__app.extensions[self.__EXT_NAME] = queue

    def enqueue(self, *nargs, **kwargs):
        queue = self.__app.extensions[self.__EXT_NAME]
        return queue.enqueue(*nargs, **kwargs)


rq_worker_queue = RqWorkerQueue()
{'fraction_non_alphanumeric': 0.10863239573229874, 'fraction_numerical': 0.0038797284190106693, 'mean_word_length': 2.664298401420959, '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': '3908172', 'n_tokens_mistral': 659, 'n_tokens_neox': 627, 'n_words': 149}