assembl.lib.model_watcher module¶
The IModelEventWatcher defines handlers for CRUD operations on certain classes.
In the assembl.models.generic.Content.send_to_changes(),
assembl.models.auth.User.send_to_changes(),
assembl.models.idea.Idea.send_to_changes() and
assembl.models.idea_content_link.Extract.send_to_changes() methods,
we call the appropriate method on the current model watcher,
given by assembl.lib.sqla.get_model_watcher(), which is a
class implementing the IModelEventWatcher protocol.
For now, the main usage is to ultimately call the
assembl.models.notification.ModelEventWatcherNotificationSubscriptionDispatcher
upon Content creation, either directly or indirectly.
Each process should call configure_model_watcher() with its process name,
so the proper model watcher is registered.
Different scenarios are defined in production.ini:
Noop: just print
Direct: Invoke the
assembl.models.notification.ModelEventWatcherNotificationSubscriptionDispatcherimmediately in-thread. (May run into issues with closed transactions.)Threaded: Send the CRUD event to another thread in the same process, using the
assembl.tasks.threaded_model_watcher.ThreadedModelEventWatcherBroker (preferred): Send the event to the
assembl.tasks.notification_dispatch.ModelEventWatcherCelerySender, which will send it through the celery machinery to theassembl.tasks.notification_dispatch.ModelEventWatcherCeleryReceiver.
-
class
assembl.lib.model_watcher.IModelEventWatcher[source]¶ An abstract interface for objects that receive CRUD events on some models
-
class
assembl.lib.model_watcher.BaseModelEventWatcher[source]¶ Bases:
objectA dummy
IModelEventWatcherfor testing purposes
-
class
assembl.lib.model_watcher.CompositeModelEventWatcher(*watchers)[source]¶ Bases:
objectA
IModelEventWatcherfor that dispatches to others
-
assembl.lib.model_watcher.configure_model_watcher(registry, task_name)[source]¶ Register the proper
IModelEventWatcherimplementation for this process according tolocal.ini
-
assembl.lib.model_watcher.get_model_watcher()[source]¶ Get the global implementation of py:class:assembl.lib.model_watcherIModelEventWatcher for this process.
Often set in
assembl.lib.model_watcher.configure_model_watcher().