def _publish(self, event, model_instance):
"""
Internal function to publish "created", "deleted", and "updated"
notification messages.
:param event: The event name ("created", "deleted", or "updated")
:type event: str
:param model_instance: The model instance upon which the event occurred
:type model_instance: commissaire.model.Model
"""
class_name = model_instance.__class__.__name__
body = {
'event': event,
'class': class_name,
'model': model_instance.to_dict_safe()
}
routing_key = 'notify.storage.{}.{}'.format(class_name, event)
if self._producer:
self.logger.debug('Publish "{}": {}'.format(routing_key, body))
self._producer.publish(
body, routing_key,
kombu.Exchange.TRANSIENT_DELIVERY_MODE)
else:
# This means the connect() method was not called.
self.logger.warn('Not publishing "%s"', routing_key)
评论列表
文章目录