-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added retry decorator to retry exceptions
- Loading branch information
Showing
2 changed files
with
90 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
def round_down(x: float, precision: int) -> int: | ||
return round(x - 5 * (10 ** (-precision - 1)), precision) | ||
|
||
|
||
def retry(max_retries, on_fail): | ||
def wrapper(fn): | ||
def inner(*args, **kwargs): | ||
so_far = 0 | ||
exceptions = set() | ||
while so_far <= max_retries: | ||
try: | ||
return fn(*args, **kwargs) | ||
except Exception as e: | ||
exceptions.add(str(e)) | ||
so_far += 1 | ||
return on_fail('\n========'.join(exceptions)) | ||
return inner | ||
return wrapper |