Commit 30b5822b by Nimisha Asthagiri

Storage-backed versioned Block Structures: Config

parent 78644495
"""
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)
...@@ -5,22 +5,19 @@ from django.conf import settings ...@@ -5,22 +5,19 @@ from django.conf import settings
from django.dispatch.dispatcher import receiver from django.dispatch.dispatcher import receiver
from xmodule.modulestore.django import SignalHandler from xmodule.modulestore.django import SignalHandler
from waffle import switch_is_active
from . import config
from .api import clear_course_from_cache from .api import clear_course_from_cache
from .tasks import update_course_in_cache from .tasks import update_course_in_cache
INVALIDATE_CACHE_ON_PUBLISH_SWITCH = 'block_structure_invalidate_cache_on_publish'
@receiver(SignalHandler.course_published) @receiver(SignalHandler.course_published)
def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument 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 Catches the signal that a course has been published in the module
store and creates/updates the corresponding cache entry. 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) clear_course_from_cache(course_key)
update_course_in_cache.apply_async( update_course_in_cache.apply_async(
......
...@@ -10,7 +10,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -10,7 +10,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from ..api import get_block_structure_manager 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 from .helpers import is_course_in_block_structure_cache
...@@ -51,7 +51,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): ...@@ -51,7 +51,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase):
def test_cache_invalidation(self, invalidate_cache_enabled, mock_bs_manager_clear): def test_cache_invalidation(self, invalidate_cache_enabled, mock_bs_manager_clear):
test_display_name = "Jedi 101" 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.course.display_name = test_display_name
self.store.update_item(self.course, self.user.id) self.store.update_item(self.course, self.user.id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment