<commit_before>import eduid_lookup_mobile.celery
from eduid_lookup_mobile.tasks import find_mobiles_by_NIN, find_NIN_by_mobile

__author__ = 'mathiashedstrom'


def init_relay(app):
    config = app.config['CELERY_CONFIG']
    config['broker_url'] = app.config['LOOKUP_MOBILE_BROKER_URL']
    eduid_lookup_mobile.celery.app.conf.update(config)
    app.lookup_mobile_relay = LookupMobileRelay()
    return app


class LookupMobileTaskFailed(Exception):
    pass


class LookupMobileRelay(object):

    def __init__(self):
        self._find_mobiles_by_NIN = find_mobiles_by_NIN
        self._find_NIN_by_mobile = find_NIN_by_mobile

    def find_nin_by_mobile(self, mobile_number):
        try:
            result = self._find_NIN_by_mobile.delay(mobile_number)
            result = result.get(timeout=10)  # Lower timeout than standard gunicorn worker timeout (25)
            return result
        except Exception as e:
            raise LookupMobileTaskFailed('find_nin_by_mobile task failed: {}'.format(e))

    def find_mobiles_by_nin(self, nin):
        try:
            result = self._find_mobiles_by_NIN.delay(nin)<commit_msg>fix tests broken by celery init changes<commit_after>import eduid_lookup_mobile

__author__ = 'mathiashedstrom'


def init_relay(app):
    app.lookup_mobile_relay = LookupMobileRelay(app.config['CELERY_CONFIG'])
    return app


class LookupMobileTaskFailed(Exception):
    pass


class LookupMobileRelay(object):

    def __init__(self, config):
        eduid_lookup_mobile.init_app(config)
        # these have to be imported _after_ eduid_lookup_mobile.init_app()
        from eduid_lookup_mobile.tasks import find_mobiles_by_NIN, find_NIN_by_mobile
        self._find_mobiles_by_NIN = find_mobiles_by_NIN
        self._find_NIN_by_mobile = find_NIN_by_mobile

    def find_nin_by_mobile(self, mobile_number):
        try:
            result = self._find_NIN_by_mobile.delay(mobile_number)
            result = result.get(timeout=10)  # Lower timeout than standard gunicorn worker timeout (25)
            return result
        except Exception as e:
            raise LookupMobileTaskFailed('find_nin_by_mobile task failed: {}'.format(e))

    def find_mobiles_by_nin(self, nin):
        try:
            result = self._find_mobiles_by_NIN.delay(nin)
{'fraction_non_alphanumeric': 0.0743006993006993, 'fraction_numerical': 0.0034965034965034965, 'mean_word_length': 3.652439024390244, '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': '3226696', 'n_tokens_mistral': 766, 'n_tokens_neox': 744, 'n_words': 137}