diff --git a/openedx/core/djangoapps/content/block_structure/config.py b/openedx/core/djangoapps/content/block_structure/config.py new file mode 100644 index 0000000000..45d994f4b5 --- /dev/null +++ b/openedx/core/djangoapps/content/block_structure/config.py @@ -0,0 +1,28 @@ +""" +This module contains various configuration settings via +waffle switches for the Block Structure framework. +""" + +from waffle import switch_is_active + + +INVALIDATE_CACHE_ON_PUBLISH = u'invalidate_cache_on_publish' +STORAGE_BACKING_FOR_CACHE = u'storage_backing_for_cache' +RAISE_ERROR_WHEN_NOT_FOUND = u'raise_error_when_not_found' + + +def is_enabled(setting_name): + """ + Returns whether the given setting is enabled. + """ + return switch_is_active( + waffle_switch_name(setting_name) + ) + + +def waffle_switch_name(setting_name): + """ + Returns the name of the waffle switch for the + given name of the setting. + """ + return u'block_structure.{}'.format(setting_name) diff --git a/openedx/core/djangoapps/content/block_structure/signals.py b/openedx/core/djangoapps/content/block_structure/signals.py index 99ded2de90..51daf20931 100644 --- a/openedx/core/djangoapps/content/block_structure/signals.py +++ b/openedx/core/djangoapps/content/block_structure/signals.py @@ -5,22 +5,19 @@ from django.conf import settings from django.dispatch.dispatcher import receiver from xmodule.modulestore.django import SignalHandler -from waffle import switch_is_active +from . import config from .api import clear_course_from_cache from .tasks import update_course_in_cache -INVALIDATE_CACHE_ON_PUBLISH_SWITCH = 'block_structure_invalidate_cache_on_publish' - - @receiver(SignalHandler.course_published) def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument """ Catches the signal that a course has been published in the module store and creates/updates the corresponding cache entry. """ - if switch_is_active(INVALIDATE_CACHE_ON_PUBLISH_SWITCH): + if config.is_enabled(config.INVALIDATE_CACHE_ON_PUBLISH): clear_course_from_cache(course_key) update_course_in_cache.apply_async( diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index e2a4843559..c60a406681 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -10,7 +10,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory from ..api import get_block_structure_manager -from ..signals import INVALIDATE_CACHE_ON_PUBLISH_SWITCH +from ..config import INVALIDATE_CACHE_ON_PUBLISH, waffle_switch_name from .helpers import is_course_in_block_structure_cache @@ -53,7 +53,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): def test_cache_invalidation(self, invalidate_cache_enabled, mock_bs_manager_clear): test_display_name = "Jedi 101" - with override_switch(INVALIDATE_CACHE_ON_PUBLISH_SWITCH, active=invalidate_cache_enabled): + with override_switch(waffle_switch_name(INVALIDATE_CACHE_ON_PUBLISH), active=invalidate_cache_enabled): self.course.display_name = test_display_name self.store.update_item(self.course, self.user.id)