changeset 3588:2c7a52a62be3

plugin XEP-0060: events callbacks can now be sync or async
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 17:10:36 +0200
parents 2715da5b2aa7
children ed037c98df37
files sat/plugins/plugin_xep_0060.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py	Thu Jul 29 15:54:54 2021 +0200
+++ b/sat/plugins/plugin_xep_0060.py	Thu Jul 29 17:10:36 2021 +0200
@@ -37,6 +37,7 @@
 from sat.core.log import getLogger
 from sat.core.core_types import SatXMPPEntity
 from sat.core import exceptions
+from sat.tools import utils
 from sat.tools import sat_defer
 from sat.tools import xml_tools
 from sat.tools.common import data_format
@@ -1507,7 +1508,10 @@
     def itemsReceived(self, event):
         log.debug("Pubsub items received")
         for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
-            callback(self.parent, event)
+            d = utils.asDeferred(callback, self.parent, event)
+            d.addErrback(lambda f: log.error(
+                f"Error while running items event callback {callback}: {f}"
+            ))
         client = self.parent
         if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
             raw_items = [i.toXml() for i in event.items]
@@ -1522,7 +1526,10 @@
     def deleteReceived(self, event):
         log.debug(("Publish node deleted"))
         for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE):
-            callback(self.parent, event)
+            d = utils.asDeferred(callback, self.parent, event)
+            d.addErrback(lambda f: log.error(
+                f"Error while running delete event callback {callback}: {f}"
+            ))
         client = self.parent
         if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
             self.host.bridge.psEventRaw(