Commit 74d7b2a7 by Davorin Sego

a different take

parent a2dbd403
......@@ -23,6 +23,7 @@ from xblock.plugin import default_select
from .exceptions import InvalidLocationError, InsufficientSpecificationError
from xmodule.errortracker import make_error_tracker
from xmodule.assetstore import AssetMetadata
from xmodule.modulestore.django import NullSignalHandler
from opaque_keys.edx.keys import CourseKey, UsageKey, AssetKey
from opaque_keys.edx.locations import Location # For import backwards compatibility
from xblock.runtime import Mixologist
......@@ -154,17 +155,6 @@ 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
......@@ -180,23 +170,7 @@ 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
@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
self.signal_handler = NullSignalHandler()
@contextmanager
def bulk_operations(self, course_id, emit_signals=True):
......
......@@ -110,6 +110,17 @@ class SignalHandler(object):
log.info('Sent %s signal to %s with kwargs %s. Response was: %s', signal_name, receiver, kwargs, response)
class NullSignalHandler(object):
"""
A null handler that does nothing
"""
def send(self, *args, **kwargs):
"""
No-op
"""
pass
def load_function(path):
"""
Load a function by name.
......
......@@ -49,6 +49,7 @@ from xmodule.modulestore.edit_info import EditInfoRuntimeMixin
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError, ReferentialIntegrityError
from xmodule.modulestore.inheritance import InheritanceMixin, inherit_metadata, InheritanceKeyValueStore
from xmodule.modulestore.xml import CourseLocationManager
from xmodule.modulestore.django import NullSignalHandler
from xmodule.services import SettingsService
log = logging.getLogger(__name__)
......@@ -543,7 +544,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
i18n_service=None,
fs_service=None,
user_service=None,
signal_handler=None,
signal_handler=NullSignalHandler(),
retry_wait_time=0.1,
**kwargs):
"""
......
......@@ -85,6 +85,7 @@ from xmodule.error_module import ErrorDescriptor
from collections import defaultdict
from types import NoneType
from xmodule.assetstore import AssetMetadata
from xmodule.modulestore.django import NullSignalHandler
log = logging.getLogger(__name__)
......@@ -640,7 +641,8 @@ 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=None, **kwargs):
services=None, signal_handler=NullSignalHandler(),
**kwargs):
"""
:param doc_store_config: must have a host, db, and collection entries. Other common entries: port, tz_aware.
"""
......
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