# HG changeset patch # User Goffi # Date 1534004692 -7200 # Node ID 3a8e7ec4648ae96d391cd154bd2f47cb9ffce1e8 # Parent b06af19c851fe30c7444904581827513ce916434 tools (trigger, async_trigger): added no_cancel argument to point and asyncPoint when a trigger must not be cancellable diff -r b06af19c851f -r 3a8e7ec4648a sat/core/xmpp.py --- a/sat/core/xmpp.py Sat Aug 04 13:03:44 2018 +0200 +++ b/sat/core/xmpp.py Sat Aug 11 18:24:52 2018 +0200 @@ -651,7 +651,8 @@ # 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 -r b06af19c851f -r 3a8e7ec4648a sat/tools/async_trigger.py --- a/sat/tools/async_trigger.py Sat Aug 04 13:03:44 2018 +0200 +++ b/sat/tools/async_trigger.py Sat Aug 11 18:24:52 2018 +0200 @@ -31,15 +31,22 @@ 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 -r b06af19c851f -r 3a8e7ec4648a sat/tools/trigger.py --- a/sat/tools/trigger.py Sat Aug 04 13:03:44 2018 +0200 +++ b/sat/tools/trigger.py Sat Aug 11 18:24:52 2018 +0200 @@ -91,14 +91,21 @@ 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