Commit 74d7b2a7 by Davorin Sego

a different take

parent a2dbd403
...@@ -23,6 +23,7 @@ from xblock.plugin import default_select ...@@ -23,6 +23,7 @@ from xblock.plugin import default_select
from .exceptions import InvalidLocationError, InsufficientSpecificationError from .exceptions import InvalidLocationError, InsufficientSpecificationError
from xmodule.errortracker import make_error_tracker from xmodule.errortracker import make_error_tracker
from xmodule.assetstore import AssetMetadata from xmodule.assetstore import AssetMetadata
from xmodule.modulestore.django import NullSignalHandler
from opaque_keys.edx.keys import CourseKey, UsageKey, AssetKey from opaque_keys.edx.keys import CourseKey, UsageKey, AssetKey
from opaque_keys.edx.locations import Location # For import backwards compatibility from opaque_keys.edx.locations import Location # For import backwards compatibility
from xblock.runtime import Mixologist from xblock.runtime import Mixologist
...@@ -154,17 +155,6 @@ class ActiveBulkThread(threading.local): ...@@ -154,17 +155,6 @@ class ActiveBulkThread(threading.local):
self.records = defaultdict(bulk_ops_record_type) 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): class BulkOperationsMixin(object):
""" """
This implements the :meth:`bulk_operations` modulestore semantics which handles nested invocations This implements the :meth:`bulk_operations` modulestore semantics which handles nested invocations
...@@ -180,23 +170,7 @@ class BulkOperationsMixin(object): ...@@ -180,23 +170,7 @@ class BulkOperationsMixin(object):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(BulkOperationsMixin, self).__init__(*args, **kwargs) super(BulkOperationsMixin, self).__init__(*args, **kwargs)
self._active_bulk_ops = ActiveBulkThread(self._bulk_ops_record_type) self._active_bulk_ops = ActiveBulkThread(self._bulk_ops_record_type)
self._signal_handler = None self.signal_handler = NullSignalHandler()
@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 @contextmanager
def bulk_operations(self, course_id, emit_signals=True): def bulk_operations(self, course_id, emit_signals=True):
......
...@@ -110,6 +110,17 @@ class SignalHandler(object): ...@@ -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) 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): def load_function(path):
""" """
Load a function by name. Load a function by name.
......
...@@ -49,6 +49,7 @@ from xmodule.modulestore.edit_info import EditInfoRuntimeMixin ...@@ -49,6 +49,7 @@ from xmodule.modulestore.edit_info import EditInfoRuntimeMixin
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError, ReferentialIntegrityError from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateCourseError, ReferentialIntegrityError
from xmodule.modulestore.inheritance import InheritanceMixin, inherit_metadata, InheritanceKeyValueStore from xmodule.modulestore.inheritance import InheritanceMixin, inherit_metadata, InheritanceKeyValueStore
from xmodule.modulestore.xml import CourseLocationManager from xmodule.modulestore.xml import CourseLocationManager
from xmodule.modulestore.django import NullSignalHandler
from xmodule.services import SettingsService from xmodule.services import SettingsService
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -543,7 +544,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo ...@@ -543,7 +544,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
i18n_service=None, i18n_service=None,
fs_service=None, fs_service=None,
user_service=None, user_service=None,
signal_handler=None, signal_handler=NullSignalHandler(),
retry_wait_time=0.1, retry_wait_time=0.1,
**kwargs): **kwargs):
""" """
......
...@@ -85,6 +85,7 @@ from xmodule.error_module import ErrorDescriptor ...@@ -85,6 +85,7 @@ from xmodule.error_module import ErrorDescriptor
from collections import defaultdict from collections import defaultdict
from types import NoneType from types import NoneType
from xmodule.assetstore import AssetMetadata from xmodule.assetstore import AssetMetadata
from xmodule.modulestore.django import NullSignalHandler
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -640,7 +641,8 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): ...@@ -640,7 +641,8 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
default_class=None, default_class=None,
error_tracker=null_error_tracker, error_tracker=null_error_tracker,
i18n_service=None, fs_service=None, user_service=None, 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. :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