<commit_before>from celery.task import task
from corehq.apps.commtrack.consumption import recalculate_domain_consumption
from corehq.apps.locations.bulk import import_locations
from corehq.apps.locations.bulk_management import new_locations_import
from corehq.toggles import NEW_BULK_LOCATION_MANAGEMENT
from corehq.util.decorators import serial_task
from corehq.util.spreadsheets.excel_importer import MultiExcelImporter
from django.conf import settings


@serial_task('{domain}', default_retry_delay=5 * 60, timeout=30 * 60,
    max_retries=12, queue=settings.CELERY_MAIN_QUEUE, ignore_result=False)
def import_locations_async(domain, file_ref_id):
    importer = MultiExcelImporter(import_locations_async, file_ref_id)
    if NEW_BULK_LOCATION_MANAGEMENT.enabled(domain):
        results = new_locations_import(domain, importer)
    else:
        results = list(import_locations(domain, importer))

    importer.mark_complete()

    return {
        'messages': results
    }


@task(ignore_result=True)
def recalculate_domain_consumption_task(domain):
    recalculate_domain_consumption(domain)<commit_msg>task.percent<commit_after>from celery.task import task
from corehq.apps.commtrack.consumption import recalculate_domain_consumption
from corehq.apps.locations.bulk import import_locations
from corehq.apps.locations.bulk_management import new_locations_import
from corehq.toggles import NEW_BULK_LOCATION_MANAGEMENT
from corehq.util.decorators import serial_task
from corehq.util.spreadsheets.excel_importer import MultiExcelImporter
from django.conf import settings
from soil import DownloadBase


@serial_task('{domain}', default_retry_delay=5 * 60, timeout=30 * 60,
    max_retries=12, queue=settings.CELERY_MAIN_QUEUE, ignore_result=False)
def import_locations_async(domain, file_ref_id):
    importer = MultiExcelImporter(import_locations_async, file_ref_id)
    task = import_locations_async
    DownloadBase.set_progress(task, 0, 100)
    if NEW_BULK_LOCATION_MANAGEMENT.enabled(domain):
        results = new_locations_import(domain, importer)
    else:
        results = list(import_locations(domain, importer))
    DownloadBase.set_progress(task, 100, 100)
    importer.mark_complete()

    return {
        'messages': results
    }


@task(ignore_result=True)
def recalculate_domain_consumption_task(domain):
    recalculate_domain_consumption(domain)
{'fraction_non_alphanumeric': 0.07251264755480608, 'fraction_numerical': 0.011804384485666104, 'mean_word_length': 6.1909090909090905, '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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5654517', 'n_tokens_mistral': 790, 'n_tokens_neox': 738, 'n_words': 137}