ox.resilience

package ox.resilience

Members list

Type members

Classlikes

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 RetryConfig[E, T](schedule: Schedule, resultPolicy: ResultPolicy[E, T], onRetry: (Int, Either[E, T]) => Unit)

A config that defines how to retry a failed operation.

A config that defines how to retry a failed operation.

It is a special case of ScheduledConfig with ScheduledConfig.sleepMode always set to SleepMode.Delay

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

onRetry

A function that is invoked after each retry attempt. The callback receives the number of the current retry attempt (starting from 1) and the result of the operation that was attempted. The result is either a successful value or an error. The callback can be used to log information about the retry attempts, or to perform other side effects. By default, the callback does nothing.

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 RetryConfig

Attributes

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

Value members

Concrete methods

def retry[T](config: RetryConfig[Throwable, T])(operation: => T): T

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

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

retry is a special case of scheduled with a given set of defaults. See RetryConfig for more details.

Value parameters

config

The retry config - see RetryConfig.

operation

The operation to retry.

Attributes

Returns

The result of the function if it eventually succeeds.

Throws
anything

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

See also

scheduled

def retryEither[E, T](config: RetryConfig[E, T])(operation: => Either[E, T]): Either[E, T]

Retries an operation returning an scala.util.Either until it succeeds or the config 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 config decides to stop. Note that any exceptions thrown by the operation aren't caught and don't cause a retry to happen.

retryEither is a special case of scheduledEither with a given set of defaults. See RetryConfig for more details.

Value parameters

config

The retry config - see RetryConfig.

operation

The operation to retry.

Attributes

Returns

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

See also

scheduledEither

def retryWithErrorMode[E, F[_], T](em: ErrorMode[E, F])(config: RetryConfig[E, T])(operation: => F[T]): F[T]

Retries an operation using the given error mode until it succeeds or the config 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 config 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.

retryWithErrorMode is a special case of scheduledWithErrorMode with a given set of defaults. See RetryConfig for more details.

Value parameters

config

The retry config - see RetryConfig.

em

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

operation

The operation to retry.

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 config decides to stop.
See also

scheduledWithErrorMode