diff --git a/dbxio/__init__.py b/dbxio/__init__.py index 99f54ab..c4a3cd4 100644 --- a/dbxio/__init__.py +++ b/dbxio/__init__.py @@ -4,4 +4,4 @@ from dbxio.utils import * # noqa: F403 from dbxio.volume import * # noqa: F403 -__version__ = '0.5.1' # single source of truth +__version__ = '0.5.2' # single source of truth diff --git a/dbxio/core/settings.py b/dbxio/core/settings.py index de89c5b..a3cde55 100644 --- a/dbxio/core/settings.py +++ b/dbxio/core/settings.py @@ -19,7 +19,7 @@ def _cloud_provider_factory() -> CloudProvider: @attrs.frozen class RetryConfig: - max_attempts: int = attrs.field(default=7, validator=[attrs.validators.instance_of(int), attrs.validators.ge(1)]) + max_attempts: int = attrs.field(default=7, validator=[attrs.validators.instance_of(int), attrs.validators.ge(0)]) exponential_backoff_multiplier: Union[float, int] = attrs.field( default=1.0, validator=[attrs.validators.instance_of((float, int)), attrs.validators.ge(0)], @@ -32,6 +32,10 @@ class RetryConfig: ), ) + @property + def empty(self): + return self.max_attempts == 0 + @attrs.define class Settings: diff --git a/dbxio/utils/retries.py b/dbxio/utils/retries.py index 59f3a5c..25e5e88 100644 --- a/dbxio/utils/retries.py +++ b/dbxio/utils/retries.py @@ -1,5 +1,5 @@ import logging -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Callable from azure.core.exceptions import AzureError from databricks.sdk.errors.platform import PermissionDenied @@ -36,7 +36,20 @@ def _clear_client_cache(call_state: RetryCallState) -> None: return +class NoRetrying(Retrying): + def __call__( + self, + fn: Callable[..., Any], + *args: Any, + **kwargs: Any, + ): + return fn(*args, **kwargs) + + def build_retrying(settings: 'RetryConfig') -> Retrying: + if settings.empty: + return NoRetrying() + return Retrying( stop=stop_after_attempt(settings.max_attempts), wait=wait_exponential(multiplier=settings.exponential_backoff_multiplier),