<commit_before>"""Management command to index reddit content"""
from django.core.management.base import BaseCommand

from open_discussions.utils import now_in_utc
from search.tasks import start_recreate_index


class Command(BaseCommand):
    """Indexes reddit content"""

    help = "Add content to elasticsearch index"

    def handle(self, *args, **options):
        """Index the comments and posts for the channels the user is subscribed to"""
        task = start_recreate_index.delay()
        self.stdout.write(
            "Started celery task {task} to index content".format(task=task)
        )
        self.stdout.write("Waiting on task...")
        start = now_in_utc()
        task.get()
        total_seconds = (now_in_utc() - start).total_seconds()
        self.stdout.write(
            "Recreate index finished, took {} seconds".format(total_seconds)
        )<commit_msg>Fix recreate_index error handling (#1620)<commit_after>"""Management command to index reddit content"""
from django.core.management.base import BaseCommand, CommandError

from open_discussions.utils import now_in_utc
from search.tasks import start_recreate_index


class Command(BaseCommand):
    """Indexes reddit content"""

    help = "Add content to elasticsearch index"

    def handle(self, *args, **options):
        """Index the comments and posts for the channels the user is subscribed to"""
        task = start_recreate_index.delay()
        self.stdout.write(
            "Started celery task {task} to index content".format(task=task)
        )
        self.stdout.write("Waiting on task...")
        start = now_in_utc()
        error = task.get()
        if error:
            raise CommandError(f"Recreate index errored: {error}")

        total_seconds = (now_in_utc() - start).total_seconds()
        self.stdout.write(
            "Recreate index finished, took {} seconds".format(total_seconds)
        )
{'fraction_non_alphanumeric': 0.10292580982236155, 'fraction_numerical': 0.0020898641588296763, 'mean_word_length': 3.040084388185654, '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': '4730069', 'n_tokens_mistral': 533, 'n_tokens_neox': 519, 'n_words': 155}