ox.retry

package ox.retry

Members list

Type members

Classlikes

enum Jitter

A random factor used for calculating the delay between subsequent retries when a backoff strategy is used for calculating the delay.

A random factor used for calculating the delay between subsequent retries when a backoff strategy is used for calculating the delay.

The purpose of jitter is to avoid clustering of subsequent retries, i.e. to reduce the number of clients calling a service exactly at the same time - which can result in subsequent failures, contrary to what you would expect from retrying. By introducing randomness to the delays, the retries become more evenly distributed over time.

See the AWS Architecture Blog article on backoff and jitter for a more in-depth explanation.

Depending on the algorithm, the jitter can affect the delay in different ways - see the concrete variants for more details.

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class ResultPolicy[E, T](isSuccess: T => Boolean, isWorthRetrying: E => Boolean)

A policy that allows to customize when a non-erroneous result is considered successful and when an error is worth retrying (which allows for failing fast on certain errors).

A policy that allows to customize when a non-erroneous result is considered successful and when an error is worth retrying (which allows for failing fast on certain errors).

Type parameters

E

The error type of the operation. For operations returning a T or a Try[T], this is fixed to Throwable. For operations returning an Either[E, T], this can be any E.

T

The successful result type for the operation.

Value parameters

isSuccess

A function that determines whether a non-erroneous result is considered successful. By default, every non-erroneous result is considered successful.

isWorthRetrying

A function that determines whether an error is worth retrying. By default, all errors are retried.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object ResultPolicy

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class RetryPolicy[E, T](schedule: Schedule, resultPolicy: ResultPolicy[E, T])

A policy that defines how to retry a failed operation.

A policy that defines how to retry a failed operation.

Type parameters

E

The error type of the operation. For operations returning a T or a Try[T], this is fixed to Throwable. For operations returning an Either[E, T], this can be any E.

T

The successful result type for the operation.

Value parameters

resultPolicy

A policy that allows to customize when a non-erroneous result is considered successful and when an error is worth retrying (which allows for failing fast on certain errors). See ResultPolicy for more details.

schedule

The retry schedule which determines the maximum number of retries and the delay between subsequent attempts to execute the operation. See Schedule for more details.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object RetryPolicy

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object Schedule

Attributes

Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Schedule.type

Value members

Concrete methods

def retry[T](operation: => T)(policy: RetryPolicy[Throwable, T]): T

Retries an operation returning a direct result until it succeeds or the policy decides to stop.

Retries an operation returning a direct result until it succeeds or the policy decides to stop.

Value parameters

operation

The operation to retry.

policy

The retry policy - see RetryPolicy.

Attributes

Returns

The result of the function if it eventually succeeds.

Throws
anything

The exception thrown by the last attempt if the policy decides to stop.

def retry[E, F[_], T](em: ErrorMode[E, F])(operation: => F[T])(policy: RetryPolicy[E, T]): F[T]

Retries an operation using the given error mode until it succeeds or the policy decides to stop. Note that any exceptions thrown by the operation aren't caught (unless the operation catches them as part of its implementation) and don't cause a retry to happen.

Retries an operation using the given error mode until it succeeds or the policy decides to stop. Note that any exceptions thrown by the operation aren't caught (unless the operation catches them as part of its implementation) and don't cause a retry to happen.

Value parameters

em

The error mode to use, which specifies when a result value is considered success, and when a failure.

operation

The operation to retry.

policy

The retry policy - see RetryPolicy.

Attributes

Returns

Either:

  • the result of the function if it eventually succeeds, in the context of F, as dictated by the error mode.
  • the error E in context F as returned by the last attempt if the policy decides to stop.
def retryEither[E, T](operation: => Either[E, T])(policy: RetryPolicy[E, T]): Either[E, T]

Retries an operation returning an scala.util.Either until it succeeds or the policy decides to stop. Note that any exceptions thrown by the operation aren't caught and don't cause a retry to happen.

Retries an operation returning an scala.util.Either until it succeeds or the policy decides to stop. Note that any exceptions thrown by the operation aren't caught and don't cause a retry to happen.

Value parameters

operation

The operation to retry.

policy

The retry policy - see RetryPolicy.

Attributes

Returns

A scala.util.Right if the function eventually succeeds, or, otherwise, a scala.util.Left with the error from the last attempt.