def update_courses_cache(course_ids):
    """
    Updates course cache so API returns updated data
    """
    for course_id in course_ids:
        course_key = CourseKey.from_string(course_id)
        update_course_in_cache(course_key)
예제 #2
0
def update_course_in_cache(course_id):
    """
    Updates the course blocks (in the database) for the specified course.
    """
    try:
        course_key = CourseKey.from_string(course_id)
        api.update_course_in_cache(course_key)
    except Exception as exc:   # pylint: disable=broad-except
        # TODO: TNL-5799, check splunk logs to narrow down the broad except above
        log.info("update_course_in_cache. Retry #{} for this task, exception: {}".format(
            update_course_in_cache.request.retries,
            repr(exc)
        ))
        raise update_course_in_cache.retry(args=[course_id], exc=exc)
예제 #3
0
    def handle(self, *args, **options):

        if options.get('all'):
            course_keys = [
                course.id for course in modulestore().get_course_summaries()
            ]
        else:
            if len(args) < 1:
                raise CommandError(
                    'At least one course or --all must be specified.')
            try:
                course_keys = [CourseKey.from_string(arg) for arg in args]
            except InvalidKeyError:
                raise CommandError('Invalid key specified.')

        log.info('Generating course blocks for %d courses.', len(course_keys))
        log.debug('Generating course blocks for the following courses: %s',
                  course_keys)

        for course_key in course_keys:
            try:
                if options.get('force'):
                    block_structure = update_course_in_cache(course_key)
                else:
                    block_structure = get_course_in_cache(course_key)
                if options.get('dags'):
                    self._find_and_log_dags(block_structure, course_key)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    'An error occurred while generating course blocks for %s: %s',
                    unicode(course_key),
                    ex.message,
                )

        log.info('Finished generating course blocks.')
    def handle(self, *args, **options):

        if options.get('all'):
            course_keys = [course.id for course in modulestore().get_course_summaries()]
        else:
            if len(args) < 1:
                raise CommandError('At least one course or --all must be specified.')
            try:
                course_keys = [CourseKey.from_string(arg) for arg in args]
            except InvalidKeyError:
                raise CommandError('Invalid key specified.')

        log.info('Generating course blocks for %d courses.', len(course_keys))
        log.debug('Generating course blocks for the following courses: %s', course_keys)

        for course_key in course_keys:
            try:
                if options.get('force'):
                    block_structure = update_course_in_cache(course_key)
                else:
                    block_structure = get_course_in_cache(course_key)
                if options.get('dags'):
                    self._find_and_log_dags(block_structure, course_key)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    'An error occurred while generating course blocks for %s: %s',
                    unicode(course_key),
                    ex.message,
                )

        log.info('Finished generating course blocks.')
예제 #5
0
def update_course_in_cache(course_id):
    """
    Updates the course blocks (in the database) for the specified course.
    """
    try:
        course_key = CourseKey.from_string(course_id)
        api.update_course_in_cache(course_key)
    except NO_RETRY_TASKS as exc:
        # Known unrecoverable errors
        raise
    except RETRY_TASKS as exc:
        log.exception("update_course_in_cache encounted expected error, retrying.")
        raise update_course_in_cache.retry(args=[course_id], exc=exc)
    except Exception as exc:   # pylint: disable=broad-except
        log.exception("update_course_in_cache encounted unknown error. Retry #{}".format(
            update_course_in_cache.request.retries,
        ))
        raise update_course_in_cache.retry(args=[course_id], exc=exc)
예제 #6
0
def update_course_in_cache(course_id):
    """
    Updates the course blocks (in the database) for the specified course.
    """
    try:
        course_key = CourseKey.from_string(course_id)
        api.update_course_in_cache(course_key)
    except NO_RETRY_TASKS as exc:
        # Known unrecoverable errors
        raise
    except RETRY_TASKS as exc:
        log.exception(
            "update_course_in_cache encounted expected error, retrying.")
        raise update_course_in_cache.retry(args=[course_id], exc=exc)
    except Exception as exc:  # pylint: disable=broad-except
        log.exception(
            "update_course_in_cache encounted unknown error. Retry #{}".format(
                update_course_in_cache.request.retries, ))
        raise update_course_in_cache.retry(args=[course_id], exc=exc)
예제 #7
0
    def handle(self, *args, **options):

        if options.get('all'):
            course_keys = [
                course.id for course in modulestore().get_course_summaries()
            ]
            if options.get('start'):
                end = options.get('end') or len(course_keys)
                course_keys = course_keys[options['start']:end]
        else:
            if len(args) < 1:
                raise CommandError(
                    'At least one course or --all must be specified.')
            try:
                course_keys = [CourseKey.from_string(arg) for arg in args]
            except InvalidKeyError:
                raise CommandError('Invalid key specified.')

        log.info('Generating course blocks for %d courses.', len(course_keys))

        if options.get('verbose'):
            log.setLevel(logging.DEBUG)
        else:
            log.setLevel(logging.CRITICAL)

        dag_info = _DAGInfo()
        for course_key in course_keys:
            try:
                if options.get('force'):
                    block_structure = update_course_in_cache(course_key)
                else:
                    block_structure = get_course_in_cache(course_key)
                if options.get('dags'):
                    self._find_and_log_dags(block_structure, course_key,
                                            dag_info)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    'An error occurred while generating course blocks for %s: %s',
                    unicode(course_key),
                    ex.message,
                )

        log.info('Finished generating course blocks.')

        if options.get('dags'):
            log.critical('DAG data: %s', unicode(dag_info))
    def handle(self, *args, **options):

        if options.get("all"):
            course_keys = [course.id for course in modulestore().get_course_summaries()]
            if options.get("start"):
                end = options.get("end") or len(course_keys)
                course_keys = course_keys[options["start"] : end]
        else:
            if len(args) < 1:
                raise CommandError("At least one course or --all must be specified.")
            try:
                course_keys = [CourseKey.from_string(arg) for arg in args]
            except InvalidKeyError:
                raise CommandError("Invalid key specified.")

        log.info("Generating course blocks for %d courses.", len(course_keys))

        if options.get("verbose"):
            log.setLevel(logging.DEBUG)
        else:
            log.setLevel(logging.CRITICAL)

        dag_info = _DAGInfo()
        for course_key in course_keys:
            try:
                if options.get("force"):
                    block_structure = update_course_in_cache(course_key)
                else:
                    block_structure = get_course_in_cache(course_key)
                if options.get("dags"):
                    self._find_and_log_dags(block_structure, course_key, dag_info)
            except Exception as ex:  # pylint: disable=broad-except
                log.exception(
                    "An error occurred while generating course blocks for %s: %s", unicode(course_key), ex.message
                )

        log.info("Finished generating course blocks.")

        if options.get("dags"):
            log.critical("DAG data: %s", unicode(dag_info))
예제 #9
0
def update_course_in_cache(course_key):
    """
    Updates the course blocks (in the database) for the specified course.
    """
    course_key = CourseKey.from_string(course_key)
    api.update_course_in_cache(course_key)