comparison sat/tools/async_trigger.py @ 2650:3a8e7ec4648a

tools (trigger, async_trigger): added no_cancel argument to point and asyncPoint when a trigger must not be cancellable
author Goffi <goffi@goffi.org>
date Sat, 11 Aug 2018 18:24:52 +0200
parents f2cf1daa42cb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2649:b06af19c851f 2650:3a8e7ec4648a
29 def asyncPoint(self, point_name, *args, **kwargs): 29 def asyncPoint(self, point_name, *args, **kwargs):
30 """This put a trigger point with potentially async Deferred 30 """This put a trigger point with potentially async Deferred
31 31
32 All the triggers for that point will be run 32 All the triggers for that point will be run
33 @param point_name: name of the trigger point 33 @param point_name: name of the trigger point
34 @param *args: args to transmit to trigger
35 @param *kwargs: kwargs to transmit to trigger
36 if "triggers_no_cancel" is present, it will be popped out
37 when set to True, this argument don't let triggers stop
38 the workflow
34 @return D(bool): True if the action must be continued, False else 39 @return D(bool): True if the action must be continued, False else
35 """ 40 """
36 if point_name not in self.__triggers: 41 if point_name not in self.__triggers:
37 defer.returnValue(True) 42 defer.returnValue(True)
38 43
44 can_cancel = not kwargs.pop('triggers_no_cancel', False)
45
39 for priority, trigger in self.__triggers[point_name]: 46 for priority, trigger in self.__triggers[point_name]:
40 try: 47 try:
41 cont = yield trigger(*args, **kwargs) 48 cont = yield trigger(*args, **kwargs)
42 if not cont: 49 if can_cancel and not cont:
43 defer.returnValue(False) 50 defer.returnValue(False)
44 except sync_trigger.SkipOtherTriggers: 51 except sync_trigger.SkipOtherTriggers:
45 break 52 break
46 defer.returnValue(True) 53 defer.returnValue(True)