Initial idea
This commit is contained in:
@@ -154,6 +154,17 @@ class ActiveBulkThread(threading.local):
|
||||
self.records = defaultdict(bulk_ops_record_type)
|
||||
|
||||
|
||||
class NullSignalHandler(object):
|
||||
"""
|
||||
A null handler that does nothing
|
||||
"""
|
||||
def send(self, *args, **kwargs):
|
||||
"""
|
||||
No-op
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class BulkOperationsMixin(object):
|
||||
"""
|
||||
This implements the :meth:`bulk_operations` modulestore semantics which handles nested invocations
|
||||
@@ -169,7 +180,23 @@ class BulkOperationsMixin(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(BulkOperationsMixin, self).__init__(*args, **kwargs)
|
||||
self._active_bulk_ops = ActiveBulkThread(self._bulk_ops_record_type)
|
||||
self.signal_handler = None
|
||||
self._signal_handler = None
|
||||
|
||||
@property
|
||||
def signal_handler(self):
|
||||
"""
|
||||
Return a signal handler, defaults to a null handler that does nothing.
|
||||
"""
|
||||
if not self._signal_handler:
|
||||
self._signal_handler = NullSignalHandler()
|
||||
return self._signal_handler
|
||||
|
||||
@signal_handler.setter
|
||||
def signal_handler(self, value):
|
||||
"""
|
||||
Set the signal handler
|
||||
"""
|
||||
self._signal_handler = value
|
||||
|
||||
@contextmanager
|
||||
def bulk_operations(self, course_id, emit_signals=True):
|
||||
|
||||
@@ -26,7 +26,6 @@ from xmodule.contentstore.django import contentstore
|
||||
from xmodule.modulestore.draft_and_published import BranchSettingMixin
|
||||
from xmodule.modulestore.mixed import MixedModuleStore
|
||||
from xmodule.util.django import get_current_request_hostname
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
import xblock.reference.plugins
|
||||
|
||||
|
||||
@@ -130,7 +129,7 @@ def create_modulestore_instance(
|
||||
i18n_service=None,
|
||||
fs_service=None,
|
||||
user_service=None,
|
||||
signal_handler=NullHandler(),
|
||||
signal_handler=None,
|
||||
):
|
||||
"""
|
||||
This will return a new instance of a modulestore given an engine and options
|
||||
|
||||
@@ -16,7 +16,6 @@ from opaque_keys.edx.keys import CourseKey, AssetKey
|
||||
from opaque_keys.edx.locator import LibraryLocator
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
from xmodule.assetstore import AssetMetadata
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
|
||||
from . import ModuleStoreWriteBase
|
||||
from . import ModuleStoreEnum
|
||||
@@ -109,7 +108,7 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
|
||||
fs_service=None,
|
||||
user_service=None,
|
||||
create_modulestore_instance=None,
|
||||
signal_handler=NullHandler(),
|
||||
signal_handler=None,
|
||||
**kwargs
|
||||
):
|
||||
"""
|
||||
|
||||
@@ -50,7 +50,6 @@ from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseErr
|
||||
from xmodule.modulestore.inheritance import InheritanceMixin, inherit_metadata, InheritanceKeyValueStore
|
||||
from xmodule.modulestore.xml import CourseLocationManager
|
||||
from xmodule.services import SettingsService
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -544,7 +543,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
i18n_service=None,
|
||||
fs_service=None,
|
||||
user_service=None,
|
||||
signal_handler=NullHandler(),
|
||||
signal_handler=None,
|
||||
retry_wait_time=0.1,
|
||||
**kwargs):
|
||||
"""
|
||||
|
||||
@@ -67,7 +67,6 @@ from bson.objectid import ObjectId
|
||||
from xblock.core import XBlock
|
||||
from xblock.fields import Scope, Reference, ReferenceList, ReferenceValueDict
|
||||
from xmodule.errortracker import null_error_tracker
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
from opaque_keys.edx.locator import (
|
||||
BlockUsageLocator, DefinitionLocator, CourseLocator, LibraryLocator, VersionTree, LocalId,
|
||||
)
|
||||
@@ -641,7 +640,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
default_class=None,
|
||||
error_tracker=null_error_tracker,
|
||||
i18n_service=None, fs_service=None, user_service=None,
|
||||
services=None, signal_handler=NullHandler(), **kwargs):
|
||||
services=None, signal_handler=None, **kwargs):
|
||||
"""
|
||||
:param doc_store_config: must have a host, db, and collection entries. Other common entries: port, tz_aware.
|
||||
"""
|
||||
|
||||
@@ -6,7 +6,6 @@ from opaque_keys.edx.keys import UsageKey
|
||||
from unittest import TestCase
|
||||
from xblock.fields import XBlockMixin
|
||||
from xmodule.x_module import XModuleMixin
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.draft_and_published import ModuleStoreDraftAndPublished
|
||||
from xmodule.modulestore.edit_info import EditInfoMixin
|
||||
@@ -37,7 +36,7 @@ def create_modulestore_instance(
|
||||
i18n_service=None,
|
||||
fs_service=None,
|
||||
user_service=None,
|
||||
signal_handler=NullHandler(),
|
||||
signal_handler=None,
|
||||
):
|
||||
"""
|
||||
This will return a new instance of a modulestore given an engine and options
|
||||
|
||||
@@ -26,7 +26,6 @@ from xmodule.x_module import (
|
||||
from xmodule.modulestore.xml_exporter import DEFAULT_CONTENT_FIELDS
|
||||
from xmodule.modulestore import ModuleStoreEnum, ModuleStoreReadBase, LIBRARY_ROOT, COURSE_ROOT
|
||||
from xmodule.tabs import CourseTabList
|
||||
from xmodule.util.null_handler import NullHandler
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey, Location
|
||||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator
|
||||
|
||||
@@ -336,7 +335,7 @@ class XMLModuleStore(ModuleStoreReadBase):
|
||||
def __init__(
|
||||
self, data_dir, default_class=None, source_dirs=None, course_ids=None,
|
||||
load_error_modules=True, i18n_service=None, fs_service=None, user_service=None,
|
||||
signal_handler=NullHandler(), target_course_id=None, **kwargs # pylint: disable=unused-argument
|
||||
signal_handler=None, target_course_id=None, **kwargs # pylint: disable=unused-argument
|
||||
):
|
||||
"""
|
||||
Initialize an XMLModuleStore from data_dir
|
||||
|
||||
Reference in New Issue
Block a user