Commit d3cd5e31 authored by Rafael Monnerat's avatar Rafael Monnerat

Implement much more network tolerant RPC call.

parent 9bc65393
...@@ -14,6 +14,7 @@ import slapos.slap ...@@ -14,6 +14,7 @@ import slapos.slap
from slapos.grid.utils import setRunning, setFinished from slapos.grid.utils import setRunning, setFinished
from erp5.util.taskdistribution import TaskDistributionTool, RPCRetry from erp5.util.taskdistribution import TaskDistributionTool, RPCRetry
from erp5.util.taskdistribution import SAFE_RPC_EXCEPTION_LIST from erp5.util.taskdistribution import SAFE_RPC_EXCEPTION_LIST
class AutoSTemp(object): class AutoSTemp(object):
""" """
Create a self-destructing temporary file. Create a self-destructing temporary file.
...@@ -95,29 +96,25 @@ class x509Transport(xmlrpclib.Transport): ...@@ -95,29 +96,25 @@ class x509Transport(xmlrpclib.Transport):
class TestTimeout(Exception): class TestTimeout(Exception):
pass pass
MAX_RETRY_ON_NETWORK_FAILURE = 10
DELAY_BETWEEN_RETRY = 10
# Simple decorator to prevent raise due small # Simple decorator to prevent raise due small
# network failures. # network failures.
def retryOnNetworkFailure(func): def retryOnNetworkFailure(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
for count in range(MAX_RETRY_ON_NETWORK_FAILURE): retry_time = 64
while True:
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except SAFE_RPC_EXCEPTION_LIST, e: except SAFE_RPC_EXCEPTION_LIST, e:
print "Network failure (%s): %s , %s" % (count, sys.exc_info(), e) print 'Network failure: %s , %s' % (sys.exc_info(), e)
time.sleep(DELAY_BETWEEN_RETRY)
# Last try should raise normally print 'Retry method %s in %i seconds' % (func, retry_time)
return func(*args, **kwargs) time.sleep(retry_time)
retry_time += retry_time >> 1
wrapper.__name__ = func.__name__ wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__ wrapper.__doc__ = func.__doc__
return wrapper return wrapper
class SoftwareReleaseTester(RPCRetry): class SoftwareReleaseTester(RPCRetry):
deadline = None deadline = None
latest_state = None latest_state = None
......
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