From c5c46f35580ffaa711ccb1f768067f3837c9e87e Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 11 Aug 2018 18:24:52 +0200 Subject: [PATCH] tools (trigger, async_trigger): added no_cancel argument to point and asyncPoint when a trigger must not be cancellable --- sat/core/xmpp.py | 3 ++- sat/tools/async_trigger.py | 9 ++++++++- sat/tools/trigger.py | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index 18e3ec45..1c87493c 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -651,7 +651,8 @@ class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient): # This is intented for e2e encryption which doesn't do full stanza # encryption (e.g. OTR) # This trigger point can't cancel the method - yield self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data) + yield self.host_app.trigger.asyncPoint("sendMessageData", self, mess_data, + triggers_no_cancel=True) self.send(mess_data[u"xml"]) defer.returnValue(mess_data) diff --git a/sat/tools/async_trigger.py b/sat/tools/async_trigger.py index 0c83ff78..56f8a197 100644 --- a/sat/tools/async_trigger.py +++ b/sat/tools/async_trigger.py @@ -31,15 +31,22 @@ class TriggerManager(sync_trigger.TriggerManager): All the triggers for that point will be run @param point_name: name of the trigger point + @param *args: args to transmit to trigger + @param *kwargs: kwargs to transmit to trigger + if "triggers_no_cancel" is present, it will be popped out + when set to True, this argument don't let triggers stop + the workflow @return D(bool): True if the action must be continued, False else """ if point_name not in self.__triggers: defer.returnValue(True) + can_cancel = not kwargs.pop('triggers_no_cancel', False) + for priority, trigger in self.__triggers[point_name]: try: cont = yield trigger(*args, **kwargs) - if not cont: + if can_cancel and not cont: defer.returnValue(False) except sync_trigger.SkipOtherTriggers: break diff --git a/sat/tools/trigger.py b/sat/tools/trigger.py index 5e40acb7..3d4868bf 100644 --- a/sat/tools/trigger.py +++ b/sat/tools/trigger.py @@ -91,14 +91,21 @@ class TriggerManager(object): All the triggers for that point will be run @param point_name: name of the trigger point + @param *args: args to transmit to trigger + @param *kwargs: kwargs to transmit to trigger + if "triggers_no_cancel" is present, it will be popup out + when set to True, this argument don't let triggers stop + the workflow @return: True if the action must be continued, False else """ if point_name not in self.__triggers: return True + can_cancel = not kwargs.pop('triggers_no_cancel', False) + for priority, trigger in self.__triggers[point_name]: try: - if not trigger(*args, **kwargs): + if not trigger(*args, **kwargs) and can_cancel: return False except SkipOtherTriggers: break