Best way to decorate many functions with the same retry configuration?
danielloader opened this issue · comments
Daniel Loader commented
Sounds simple but trying to work out how to make my code more DRY instead of updating all the arguments to the decorator on every function.
Is this supported?
Thanks
Bernhard commented
sure, you can create your own function for this. Example:
from opnieuw import RetryException
from opnieuw import retry as retry_orig
RETRY_EXCEPTIONS = (
RetryException,
OSError,
)
def retry(max_calls_total=10, retry_window_after_first_call_in_seconds=900):
return retry_orig(
retry_on_exceptions=RETRY_EXCEPTIONS,
max_calls_total=max_calls_total,
retry_window_after_first_call_in_seconds=retry_window_after_first_call_in_seconds,
)
Daniel Loader commented
Thanks, perfect.
Very grateful for the library!