Files
edx-platform/openedx/core/djangoapps/util/signals.py
Amit 13fc8a7dd5 INCR-240 (#20509)
* INCR-240: Run python-modernize and isort on openedx/core/djangoapps/util

* INCR-240: [ADD] Missing module docstring at ratelimit
2019-05-10 11:23:05 -04:00

35 lines
899 B
Python

"""
Signal handler for exceptions.
"""
# pylint: disable=unused-argument
from __future__ import absolute_import
import logging
from celery.signals import task_postrun
from django.conf import settings
from django.core.signals import got_request_exception
from django.dispatch import receiver
from edx_django_utils.cache import RequestCache
@receiver(got_request_exception)
def record_request_exception(sender, **kwargs):
"""
Logs the stack trace whenever an exception
occurs in processing a request.
"""
logging.exception(u"Uncaught exception from {sender}".format(
sender=sender
))
@task_postrun.connect
def _clear_request_cache(**kwargs):
"""
Once a celery task completes, clear the request cache to
prevent memory leaks.
"""
if getattr(settings, 'CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION', True):
RequestCache.clear_all_namespaces()