Files
mayan-edms/mayan/apps/lock_manager/decorators.py
Roberto Rosario 09edab5027 Update lock managet app
Add keyword arguments. Sort imports. Move settings and test
literals to their own module.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
2019-01-21 02:50:34 -04:00

27 lines
713 B
Python

from __future__ import absolute_import, unicode_literals
import random
import time
from .exceptions import LockError
def retry_on_lock_error(retries):
def decorator(function):
def wrapper():
retry_count = 0
while True:
try:
return function()
except LockError:
if retry_count == retries:
raise
else:
retry_count = retry_count + 1
timeout = 2 ** retry_count
timeout = random.randrange(timeout + 1)
time.sleep(timeout)
return wrapper
return decorator