From 9d545eca4cff62f0f63c54b42aa88d83fed2f708 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 15 Dec 2016 14:35:42 -0500 Subject: [PATCH] update_course_in_cache exception handler cleanup --- .../djangoapps/content/block_structure/tasks.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content/block_structure/tasks.py b/openedx/core/djangoapps/content/block_structure/tasks.py index 3578d67f3d..adb2e371a6 100644 --- a/openedx/core/djangoapps/content/block_structure/tasks.py +++ b/openedx/core/djangoapps/content/block_structure/tasks.py @@ -2,14 +2,22 @@ Asynchronous tasks related to the Course Blocks sub-application. """ import logging +from capa.responsetypes import LoncapaProblemError from celery.task import task from django.conf import settings +from edxval.api import ValInternalError +from lxml.etree import XMLSyntaxError from opaque_keys.edx.keys import CourseKey +from xmodule.modulestore.exceptions import ItemNotFoundError from openedx.core.djangoapps.content.block_structure import api log = logging.getLogger('edx.celery.task') +# TODO: TNL-5799 is ongoing; narrow these lists down until the general exception is no longer needed +RETRY_TASKS = (ItemNotFoundError, TypeError, ValInternalError) +NO_RETRY_TASKS = (XMLSyntaxError, LoncapaProblemError, UnicodeEncodeError) + @task( default_retry_delay=settings.BLOCK_STRUCTURES_SETTINGS['BLOCK_STRUCTURES_TASK_DEFAULT_RETRY_DELAY'], @@ -22,9 +30,14 @@ def update_course_in_cache(course_id): try: course_key = CourseKey.from_string(course_id) api.update_course_in_cache(course_key) + except NO_RETRY_TASKS as exc: + log.info("update_course_in_cache encountered unrecoverable error: {}".format(exc)) + raise + except RETRY_TASKS as exc: + log.info("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 - # 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( + log.info("update_course_in_cache encounted unknown error. Retry #{}, Exception: {}".format( update_course_in_cache.request.retries, repr(exc) ))