channable / opnieuw

One weird trick to make your code more reliable

Home Page:https://tech.channable.com/posts/2020-02-05-opnieuw.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Best way to decorate many functions with the same retry configuration?

danielloader opened this issue · comments

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

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,
    )

Thanks, perfect.

Very grateful for the library!