-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- rebase circular import issue fix to core/opl - remove stale unused imports
- Loading branch information
Vishal Vijayraghavan
committed
Jun 25, 2024
1 parent
bfb3b0d
commit 2e76f35
Showing
6 changed files
with
45 additions
and
46 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
import time | ||
from functools import wraps | ||
|
||
|
||
def retry_on_traceback(max_attempts=10, wait_seconds=1): | ||
""" | ||
Retries a function until it succeeds or the maximum number of attempts | ||
or wait time is reached. | ||
This is to mimic `@retry` decorator from Tenacity so we do not depend | ||
on it. | ||
Args: | ||
max_attempts: The maximum number of attempts to retry the function. | ||
wait_seconds: The number of seconds to wait between retries. | ||
Returns: | ||
A decorator that retries the wrapped function. | ||
""" | ||
assert max_attempts >= 0, "It does not make sense to have less than 0 retries" | ||
assert wait_seconds >= 0, "It does not make sense to wait les than 0 seconds" | ||
|
||
def decorator(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
attempt = 0 | ||
while True: | ||
try: | ||
return func(*args, **kwargs) | ||
except Exception as e: | ||
if attempt >= max_attempts: | ||
raise # Reraise the exception after all retries are exhausted | ||
|
||
attempt += 1 | ||
logging.debug( | ||
f"Retrying in {wait_seconds} seconds. Attempt {attempt}/{max_attempts} failed with: {e}" | ||
) | ||
time.sleep(wait_seconds) | ||
|
||
return wrapper | ||
|
||
return decorator |
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
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,7 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import unittest | ||
import argparse | ||
import datetime | ||
|
||
from .context import opl | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import unittest | ||
import argparse | ||
import datetime | ||
|
||
from .context import opl | ||
|
||
|