-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add retries for az token (with clearing cache) (#13)
- Loading branch information
1 parent
81d69e2
commit 70e1545
Showing
8 changed files
with
155 additions
and
5 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
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
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,31 @@ | ||
from databricks.sdk.errors.platform import PermissionDenied | ||
from tenacity import RetryCallState, retry, retry_if_exception_type, stop_after_attempt, wait_exponential | ||
|
||
|
||
def _clear_client_cache(call_state: RetryCallState) -> None: | ||
""" | ||
Gets all argument of the function from retry state, finds the client and clears its cache. | ||
""" | ||
if call_state.attempt_number == 1: | ||
# Do not clear cache on the first attempt | ||
return | ||
|
||
from dbxio.core.client import DbxIOClient | ||
|
||
for arg in call_state.args: | ||
if isinstance(arg, DbxIOClient): | ||
arg.clear_cache() | ||
return | ||
for arg in call_state.kwargs.values(): | ||
if isinstance(arg, DbxIOClient): | ||
arg.clear_cache() | ||
return | ||
|
||
|
||
dbxio_retry = retry( | ||
stop=stop_after_attempt(7), | ||
wait=wait_exponential(multiplier=1), | ||
retry=retry_if_exception_type((PermissionDenied,)), | ||
reraise=True, | ||
before=_clear_client_cache, | ||
) |
Oops, something went wrong.