<commit_before>from celery.task import task, periodic_task
from celery.schedules import crontab
from .utils import filelock

from .settings import RECOMMENDS_TASK_RUN, RECOMMENDS_TASK_CRONTAB


if RECOMMENDS_TASK_RUN:

    @periodic_task(run_every=crontab(**RECOMMENDS_TASK_CRONTAB))
    def recommends_precompute():
        from .providers import recommendation_registry

        # I know this is weird, but it's faster (tested on CPyhton 2.6.5)
        def _precompute(provider_instance):
            provider_instance.precompute()

        with filelock('recommends_precompute.lock'):
            [_precompute(provider_instance) for provider_instance in recommendation_registry.get_vote_providers()]


@task
def remove_suggestions(rated_model, object_id):
    from django.db.models import get_model
    from recommends.providers import recommendation_registry

    ObjectClass = get_model(*rated_model.split('.'))
    provider_instance = recommendation_registry.get_provider_for_content(ObjectClass)
    obj = ObjectClass.objects.get(pk=object_id)

    provider_instance.storage.remove_recommendations(obj)


@task
def remove_similarities(rated_model, object_id):
    from django.db.models import get_model
    from recommends.providers import recommendation_registry

    ObjectClass = get_model(*rated_model.split('.'))
    provider_instance = recommendation_registry.get_provider_for_content(ObjectClass)
    obj = ObjectClass.objects.get(pk=object_id)

    provider_instance.storage.remove_similarities(obj)<commit_msg>explicitly named celery tasks. Thanks <NAME>.<commit_after>from celery.task import task, periodic_task
from celery.schedules import crontab
from .utils import filelock

from .settings import RECOMMENDS_TASK_RUN, RECOMMENDS_TASK_CRONTAB


if RECOMMENDS_TASK_RUN:

    @periodic_task(name='recommends_precompute', run_every=crontab(**RECOMMENDS_TASK_CRONTAB))
    def recommends_precompute():
        from .providers import recommendation_registry

        # I know this is weird, but it's faster (tested on CPyhton 2.6.5)
        def _precompute(provider_instance):
            provider_instance.precompute()

        with filelock('recommends_precompute.lock'):
            [_precompute(provider_instance) for provider_instance in recommendation_registry.get_vote_providers()]


@task(name='remove_suggestions')
def remove_suggestions(rated_model, object_id):
    from django.db.models import get_model
    from recommends.providers import recommendation_registry

    ObjectClass = get_model(*rated_model.split('.'))
    provider_instance = recommendation_registry.get_provider_for_content(ObjectClass)
    obj = ObjectClass.objects.get(pk=object_id)

    provider_instance.storage.remove_recommendations(obj)


@task(name='remove_similarities')
def remove_similarities(rated_model, object_id):
    from django.db.models import get_model
    from recommends.providers import recommendation_registry

    ObjectClass = get_model(*rated_model.split('.'))
    provider_instance = recommendation_registry.get_provider_for_content(ObjectClass)
    obj = ObjectClass.objects.get(pk=object_id)

    provider_instance.storage.remove_similarities(obj)
{'fraction_non_alphanumeric': 0.07636478384348375, 'fraction_numerical': 0.0018933417481855476, 'mean_word_length': 5.252465483234714, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1159750', 'n_tokens_mistral': 953, 'n_tokens_neox': 898, 'n_words': 179}