def transaction_atomic_with_retry(num_retries=<NUM_LIT:5>, backoff=<NUM_LIT:0.1>):
<EOL>@wrapt.decorator<EOL>def wrapper(wrapped, instance, args, kwargs):<EOL><INDENT>num_tries = <NUM_LIT:0><EOL>exception = None<EOL>while num_tries <= num_retries:<EOL><INDENT>try:<EOL><INDENT>with transaction.atomic():<EOL><INDENT>return wrapped(*args, **kwargs)<EOL><DEDENT><DEDENT>except db.utils.OperationalError as e:<EOL><INDENT>num_tries += <NUM_LIT:1><EOL>exception = e<EOL>sleep(backoff * num_tries)<EOL><DEDENT><DEDENT>raise exception<EOL><DEDENT>return wrapper<EOL>
This is a decorator that will wrap the decorated method in an atomic transaction and
retry the transaction a given number of times

:param num_retries: How many times should we retry before we give up
:param backoff: How long should we wait after each try