<commit_before># -*- coding: utf-8 -*-
"""

"""
from __future__ import absolute_import

import json
from datetime import datetime
from time import mktime
import logging
import os

from drift.utils import get_config
from flask import g

from celery import Celery
import kombu.serialization

from drift.utils import get_tier_name
from driftconfig.util import get_default_drift_config
log = logging.getLogger(__name__)

CELERY_DB_NUMBER = 15


# Global Celery instance
celery = None


def make_celery(app):

    kombu.serialization.register(
        'drift_celery_json',
        drift_celery_dumps, drift_celery_loads,
        content_type='application/x-myjson', content_encoding='utf-8'
    )

    celery = Celery(app.import_name)

    ts = get_default_drift_config()
    tier_name = get_tier_name()
    tier_config = ts.get_table('tiers').get({'tier_name': tier_name})

    if os.environ.get('DRIFT_USE_LOCAL_SERVERS', False):
        broker_url = "redis://localhost:6379/15"
    else:
        broker_url = tier_config["celery_broker_url"]

    log.info("Celery broker from tier config: %s", broker_url)

    celery.conf.update(app.config)
    celery.conf["BROKER_URL"] = broker_url
    celery.conf["CELERY_RESULT_BACKEND"] = broker_url
    celery.conf["CELERY_TASK_SERIALIZER"] = "drift_celery_json"
    celery.conf["CELERY_RESULT_SERIALIZER"] = "drift_celery_json"
    celery.conf["CELERY_ACCEPT_CONTENT"] = ["drift_celery_json"]
    celery.conf["CELERY_ENABLE_UTC"] = True
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                g.conf = get_config()
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery

<commit_msg>Celery broker url is no longer defined specifically in the config. Now it just uses the tiers default redis server. This is to simplify configuration setup.<commit_after># -*- coding: utf-8 -*-
"""

"""
from __future__ import absolute_import

import json
from datetime import datetime
from time import mktime
import logging
import os

from drift.utils import get_config
from flask import g

from celery import Celery
import kombu.serialization

from drift.utils import get_tier_name
from driftconfig.util import get_default_drift_config
log = logging.getLogger(__name__)

CELERY_DB_NUMBER = 15


# Global Celery instance
celery = None


def make_celery(app):

    kombu.serialization.register(
        'drift_celery_json',
        drift_celery_dumps, drift_celery_loads,
        content_type='application/x-myjson', content_encoding='utf-8'
    )

    celery = Celery(app.import_name)

    ts = get_default_drift_config()
    tier_name = get_tier_name()
    tier_config = ts.get_table('tiers').get({'tier_name': tier_name})

    if os.environ.get('DRIFT_USE_LOCAL_SERVERS', False):
        broker_url = "redis://localhost:6379/15"
    else:
        # HACK: Just use the tier default value instead of "celery_broker_url".
        # broker_url = tier_config["celery_broker_url"]
        broker_url = "redis://{host}:{port}/15".format(
            **tier_config['resources']['drift.core.resources.redis'])

    log.info("Celery broker from tier config: %s", broker_url)

    celery.conf.update(app.config)
    celery.conf["BROKER_URL"] = broker_url
    celery.conf["CELERY_RESULT_BACKEND"] = broker_url
    celery.conf["CELERY_TASK_SERIALIZER"] = "drift_celery_json"
    celery.conf["CELERY_RESULT_SERIALIZER"] = "drift_celery_json"
    celery.conf["CELERY_ACCEPT_CONTENT"] = ["drift_celery_json"]
    celery.conf["CELERY_ENABLE_UTC"] = True
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                g.conf = get_config()
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery


{'fraction_non_alphanumeric': 0.10315258511979823, 'fraction_numerical': 0.005548549810844893, 'mean_word_length': 3.693491124260355, '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': '2245596', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1295, 'n_words': 276}