Monitors - catch changes to model fields and Attributes.
The MONITOR_HANDLER singleton from this module offers the following functionality:
- Field-monitor - track a object’s specific database field and perform
an action whenever that field changes for whatever reason.
- Attribute-monitor tracks an object’s specific Attribute and perform
an action whenever that Attribute changes for whatever reason.
This is a resource singleton that allows for registering callbacks for when a field or Attribute is updated (saved).
Initialize the handler.
Store our monitors to the database. This is called by the server process.
Since dbserialize can’t handle defaultdicts, we convert to an intermediary save format ((obj,fieldname, idstring, callback, kwargs), …)
Restore our monitors after a reload. This is called by the server process.
server_reload (bool, optional) – If this is False, it means the server went through a cold reboot and all non-persistent tickers must be killed.
Called by the field/attribute as it saves.
add(obj, fieldname, callback, idstring='', persistent=False, **kwargs)¶
Add monitoring to a given field or Attribute. A field must be specified with the full db_* name or it will be assumed to be an Attribute (so db_key, not just key).
obj (Typeclassed Entity) – The entity on which to monitor a field or Attribute.
fieldname (str) – Name of field (db_*) or Attribute to monitor.
idstring (str, optional) – An id to separate this monitor from other monitors of the same field and object.
persistent (bool, optional) – If False, the monitor will survive a server reload but not a cold restart. This is default.
- Keyword Arguments
session (Session) – If this keyword is given, the monitorhandler will correctly analyze it and remove the monitor if after a reload/reboot the session is no longer valid.
any (any) – Any other kwargs are passed on to the callback. Remember that all kwargs must be possible to pickle!
remove(obj, fieldname, idstring='')¶
Remove a monitor.
Delete all monitors.
List all monitors or all monitors of a given object.
obj (Object) – The object on which to list all monitors.
monitors (list) – The handled monitors.