diff --git a/product/CMFActivity/ActivityRuntimeEnvironment.py b/product/CMFActivity/ActivityRuntimeEnvironment.py index 93a60a825ad2521bdb1c93f9566918b3a0544972..ea8b483995cc74dcf8d115a95e137f0e54b9e4f1 100644 --- a/product/CMFActivity/ActivityRuntimeEnvironment.py +++ b/product/CMFActivity/ActivityRuntimeEnvironment.py @@ -15,12 +15,16 @@ def _getActivityRuntimeEnvironment(): class BaseMessage: - delay = None + def __property(**kw): + (k, v), = kw.items() + return property(lambda self: self.activity_kw.get(k, v)) + + delay = __property(delay=None) # None means infinite retry - max_retry = 5 + max_retry = __property(max_retry=5) # For errors happening after message invocation (ConflictError), # should we retry quickly without increasing 'retry' count ? - conflict_retry = True + conflict_retry = __property(conflict_retry=True) class ActivityRuntimeEnvironment(object): @@ -32,4 +36,4 @@ class ActivityRuntimeEnvironment(object): # There is no point allowing to modify other attributes from a message for k in kw: getattr(BaseMessage, k) - self._message.__dict__.update(kw) + self._message.activity_kw.update(kw) diff --git a/product/CMFActivity/tests/testCMFActivity.py b/product/CMFActivity/tests/testCMFActivity.py index 90651172271a27bed3e92052ff710b6da116fb21..6dc4e06d38594fb292f6d78f162ff2d7b1ea9d22 100644 --- a/product/CMFActivity/tests/testCMFActivity.py +++ b/product/CMFActivity/tests/testCMFActivity.py @@ -1659,12 +1659,12 @@ class TestCMFActivity(ERP5TypeTestCase): self.getActivityRuntimeEnvironment().edit(**edit_kw) if conflict is not None: raise conflict and ConflictError or Exception - def check(retry_list): + def check(retry_list, **activate_kw): fail = retry_list[-1][0] is not None and 1 or 0 for activity in 'SQLDict', 'SQLQueue': exec_count[0] = 0 - activity_tool.activate(activity=activity, priority=priority(1,6)) \ - .doSomething(retry_list) + activity_tool.activate(activity=activity, priority=priority(1,6), + **activate_kw).doSomething(retry_list) get_transaction().commit() self.flushAllActivities(silent=1) self.assertEqual(len(retry_list), exec_count[0]) @@ -1687,6 +1687,7 @@ class TestCMFActivity(ERP5TypeTestCase): # ... even in case of ConflictError check([(True, {'max_retry': 0}), (True, {'max_retry': 0, 'conflict_retry': 0})]) + check([(True, None)] * 6, conflict_retry=False) # Customized number of retries for n in 3, 9: check([(False, {'max_retry': n})] * n + [(None, None)]) @@ -1696,6 +1697,7 @@ class TestCMFActivity(ERP5TypeTestCase): check([(False, {'max_retry': None})] * n + [(None, None)]) check([(False, {'max_retry': None})] * n + [(False, {'max_retry': 0})]) check([(False, {'max_retry': None})] * 9 + [(False, None)]) + finally: del activity_tool.__class__.doSomething self.assertFalse(activity_tool.getMessageList())