Skip to content

Commit

Permalink
feat: make possible to run w/o retries
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaYurasov committed Nov 12, 2024
1 parent 0775fa8 commit d2a9487
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dbxio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion dbxio/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand All @@ -32,6 +32,10 @@ class RetryConfig:
),
)

@property
def empty(self):
return self.max_attempts == 0


@attrs.define
class Settings:
Expand Down
15 changes: 14 additions & 1 deletion dbxio/utils/retries.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d2a9487

Please sign in to comment.