Example #1
0
    def handle(self, *args, **options):
        """
        By convention set by django developers, this method actually executes command's actions.
        So, there could be no better docstring than emphasize this once again.
        """
        if (not options['library_ids']
                and not options['all']) or (options['library_ids']
                                            and options['all']):
            raise CommandError(
                "reindex_library requires one or more <library_id>s or the --all flag."
            )

        store = modulestore()

        if options['all']:
            if query_yes_no(self.CONFIRMATION_PROMPT, default="no"):
                library_keys = [
                    library.location.library_key.replace(branch=None)
                    for library in store.get_libraries()
                ]
            else:
                return
        else:
            library_keys = list(
                map(self._parse_library_key, options['library_ids']))

        for library_key in library_keys:
            print(f"Indexing library {library_key}")
            LibrarySearchIndexer.do_library_reindex(store, library_key)
Example #2
0
def update_library_index(library_id, triggered_time_isoformat):
    """ Updates course search index. """
    try:
        library_key = CourseKey.from_string(library_id)
        LibrarySearchIndexer.index(modulestore(), library_key, triggered_at=(_parse_time(triggered_time_isoformat)))

    except SearchIndexingError as exc:
        LOGGER.error('Search indexing error for library %s - %s', library_id, str(exc))
    else:
        LOGGER.debug('Search indexing successful for library %s', library_id)
Example #3
0
def listen_for_library_update(sender, library_key, **kwargs):  # pylint: disable=unused-argument
    """
    Receives signal and kicks off celery task to update search index
    """

    if LibrarySearchIndexer.indexing_is_enabled():
        # import here, because signal is registered at startup, but items in tasks are not yet able to be loaded
        from cms.djangoapps.contentstore.tasks import update_library_index

        update_library_index.delay(str(library_key), datetime.now(UTC).isoformat())