exponential_backoff_mixin

Bases:

ABC
Source Code in griptape/mixins/exponential_backoff_mixin.py
@define(slots=False)
class ExponentialBackoffMixin(ABC):
    min_retry_delay: float = field(default=2, kw_only=True)
    max_retry_delay: float = field(default=10, kw_only=True)
    max_attempts: int = field(default=2, kw_only=True)
    after_hook: Callable = field(default=lambda s: logging.warning(s), kw_only=True)
    ignored_exception_types: tuple[type[Exception], ...] = field(factory=tuple, kw_only=True)

    def retrying(self) -> Retrying:
        return Retrying(
            wait=wait_exponential(min=self.min_retry_delay, max=self.max_retry_delay),
            retry=retry_if_not_exception_type(self.ignored_exception_types),
            stop=stop_after_attempt(self.max_attempts),
            reraise=True,
            after=self.after_hook,
        )
  • after_hook = field(default=lambda s: logging.warning(s), kw_only=True) class-attribute instance-attribute

  • ignored_exception_types = field(factory=tuple, kw_only=True) class-attribute instance-attribute

  • max_attempts = field(default=2, kw_only=True) class-attribute instance-attribute

  • max_retry_delay = field(default=10, kw_only=True) class-attribute instance-attribute

  • min_retry_delay = field(default=2, kw_only=True) class-attribute instance-attribute

retrying()

Source Code in griptape/mixins/exponential_backoff_mixin.py
def retrying(self) -> Retrying:
    return Retrying(
        wait=wait_exponential(min=self.min_retry_delay, max=self.max_retry_delay),
        retry=retry_if_not_exception_type(self.ignored_exception_types),
        stop=stop_after_attempt(self.max_attempts),
        reraise=True,
        after=self.after_hook,
    )

Could this page be better? Report a problem or suggest an addition!