Commit ec6d5c43 authored by Julien Muchembled's avatar Julien Muchembled

Also allow to specify retry parameters in activate_kw

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32882 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7122fe43
...@@ -15,12 +15,16 @@ def _getActivityRuntimeEnvironment(): ...@@ -15,12 +15,16 @@ def _getActivityRuntimeEnvironment():
class BaseMessage: 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 # None means infinite retry
max_retry = 5 max_retry = __property(max_retry=5)
# For errors happening after message invocation (ConflictError), # For errors happening after message invocation (ConflictError),
# should we retry quickly without increasing 'retry' count ? # should we retry quickly without increasing 'retry' count ?
conflict_retry = True conflict_retry = __property(conflict_retry=True)
class ActivityRuntimeEnvironment(object): class ActivityRuntimeEnvironment(object):
...@@ -32,4 +36,4 @@ class ActivityRuntimeEnvironment(object): ...@@ -32,4 +36,4 @@ class ActivityRuntimeEnvironment(object):
# There is no point allowing to modify other attributes from a message # There is no point allowing to modify other attributes from a message
for k in kw: for k in kw:
getattr(BaseMessage, k) getattr(BaseMessage, k)
self._message.__dict__.update(kw) self._message.activity_kw.update(kw)
...@@ -1659,12 +1659,12 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1659,12 +1659,12 @@ class TestCMFActivity(ERP5TypeTestCase):
self.getActivityRuntimeEnvironment().edit(**edit_kw) self.getActivityRuntimeEnvironment().edit(**edit_kw)
if conflict is not None: if conflict is not None:
raise conflict and ConflictError or Exception 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 fail = retry_list[-1][0] is not None and 1 or 0
for activity in 'SQLDict', 'SQLQueue': for activity in 'SQLDict', 'SQLQueue':
exec_count[0] = 0 exec_count[0] = 0
activity_tool.activate(activity=activity, priority=priority(1,6)) \ activity_tool.activate(activity=activity, priority=priority(1,6),
.doSomething(retry_list) **activate_kw).doSomething(retry_list)
get_transaction().commit() get_transaction().commit()
self.flushAllActivities(silent=1) self.flushAllActivities(silent=1)
self.assertEqual(len(retry_list), exec_count[0]) self.assertEqual(len(retry_list), exec_count[0])
...@@ -1687,6 +1687,7 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1687,6 +1687,7 @@ class TestCMFActivity(ERP5TypeTestCase):
# ... even in case of ConflictError # ... even in case of ConflictError
check([(True, {'max_retry': 0}), check([(True, {'max_retry': 0}),
(True, {'max_retry': 0, 'conflict_retry': 0})]) (True, {'max_retry': 0, 'conflict_retry': 0})])
check([(True, None)] * 6, conflict_retry=False)
# Customized number of retries # Customized number of retries
for n in 3, 9: for n in 3, 9:
check([(False, {'max_retry': n})] * n + [(None, None)]) check([(False, {'max_retry': n})] * n + [(None, None)])
...@@ -1696,6 +1697,7 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1696,6 +1697,7 @@ class TestCMFActivity(ERP5TypeTestCase):
check([(False, {'max_retry': None})] * n + [(None, None)]) check([(False, {'max_retry': None})] * n + [(None, None)])
check([(False, {'max_retry': None})] * n + [(False, {'max_retry': 0})]) check([(False, {'max_retry': None})] * n + [(False, {'max_retry': 0})])
check([(False, {'max_retry': None})] * 9 + [(False, None)]) check([(False, {'max_retry': None})] * 9 + [(False, None)])
finally: finally:
del activity_tool.__class__.doSomething del activity_tool.__class__.doSomething
self.assertFalse(activity_tool.getMessageList()) self.assertFalse(activity_tool.getMessageList())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment