Commit 633a28ab authored by Arnaud Fontaine's avatar Arnaud Fontaine

Return a tuple for the waiting time including the waiting time *and* the time

spent on the request as it could be useful to distinguish both. Also, avoid
check if the method has already been wrapped (useful when going through the
bases)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@46007 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 95e64fcc
...@@ -57,11 +57,16 @@ def measurementMetaClass(prefix): ...@@ -57,11 +57,16 @@ def measurementMetaClass(prefix):
def timeInSecondDecorator(method): def timeInSecondDecorator(method):
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
""" """
Replaced by the wrapped method docstring Replaced by the wrapped method docstring. Some methods return the
time spent on waiting (C{submitSelectJump} and for example), thus
return a tuple with the time spent on the request and the time spent
on waiting
""" """
ret = method(self, *args, **kwargs) ret = method(self, *args, **kwargs)
return (ret is None and self.lastRequestSeconds or if ret is None:
(ret + self.lastRequestSeconds)) return self.lastRequestSeconds
else:
return (self.lastRequestSeconds, ret)
return wrapper return wrapper
...@@ -77,6 +82,10 @@ def measurementMetaClass(prefix): ...@@ -77,6 +82,10 @@ def measurementMetaClass(prefix):
wrapper_method.func_name = method.func_name wrapper_method.func_name = method.func_name
wrapper_method.__doc__ = method.__doc__ wrapper_method.__doc__ = method.__doc__
# In order to avoid re-wrapping the method when looking at the bases
# for example
wrapper_method.__is_wrapper__ = True
dictionary[method.func_name] = wrapper_method dictionary[method.func_name] = wrapper_method
# Only wrap methods prefixed by the given prefix # Only wrap methods prefixed by the given prefix
...@@ -89,7 +98,7 @@ def measurementMetaClass(prefix): ...@@ -89,7 +98,7 @@ def measurementMetaClass(prefix):
if attribute_name not in dictionary and \ if attribute_name not in dictionary and \
attribute_name.startswith(prefix): attribute_name.startswith(prefix):
attribute = getattr(bases[0], attribute_name) attribute = getattr(bases[0], attribute_name)
if callable(attribute): if callable(attribute) and not getattr(attribute, '__is_wrapper__', False):
applyMeasure(attribute) applyMeasure(attribute)
# lastRequestSeconds properties are only defined on classes inheriting # lastRequestSeconds properties are only defined on classes inheriting
...@@ -780,8 +789,6 @@ class ContextMainForm(MainForm): ...@@ -780,8 +789,6 @@ class ContextMainForm(MainForm):
@type maximum_attempt_number: int @type maximum_attempt_number: int
@param sleep_between_attempt: Sleep N seconds between attempts @param sleep_between_attempt: Sleep N seconds between attempts
@type sleep_between_attempt: int @type sleep_between_attempt: int
@return: The time spent (in seconds) if relevant
@rtype: int
""" """
if not no_jump_transition_message: if not no_jump_transition_message:
self.submitSelect('select_jump', 'Base_doJump:method', self.submitSelect('select_jump', 'Base_doJump:method',
...@@ -899,32 +906,36 @@ class ContextMainForm(MainForm): ...@@ -899,32 +906,36 @@ class ContextMainForm(MainForm):
@type maximum_attempt_number: int @type maximum_attempt_number: int
@param sleep_between_attempt: Sleep N seconds between attempts @param sleep_between_attempt: Sleep N seconds between attempts
@type sleep_between_attempt: int @type sleep_between_attempt: int
@return: The time spent (in seconds) if relevant
@rtype: int
""" """
current_attempt_number = 1 def tryLegacyAndNew():
while True:
try: try:
try: self.submitSelect('select_action', 'Base_doAction:method', label,
self.submitSelect('select_action', 'Base_doAction:method', label, value and '%s?workflow_action=%s' % (script_id, value),
value and '%s?workflow_action=%s' % (script_id, value), **kw)
**kw)
except LookupError:
self.submitSelect('select_action', 'Base_doAction:method', label,
value and '%s?field_my_workflow_action=%s' % (script_id,
value),
**kw)
except LookupError: except LookupError:
if current_attempt_nbr == maximum_attempt_number: self.submitSelect('select_action', 'Base_doAction:method', label,
raise value and '%s?field_my_workflow_action=%s' % (script_id,
value),
**kw)
if maximum_attempt_number == 1:
tryLegacyAndNew()
else:
current_attempt_number = 1
while True:
try:
tryLegacyAndNew()
except LookupError:
if current_attempt_number == maximum_attempt_number:
raise
current_attempt_number += 1 current_attempt_number += 1
time.sleep(sleep_between_attempt) time.sleep(sleep_between_attempt)
else: else:
break break
return (current_attempt_number - 1) * sleep_between_attempt return (current_attempt_number - 1) * sleep_between_attempt
def submitDialogCancel(self): def submitDialogCancel(self):
""" """
......
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