ox.scheduling

package ox.scheduling

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 RepeatConfig[E, T](schedule: Schedule, shouldContinueOnResult: T => Boolean)

A config that defines how to repeat an operation.

A config that defines how to repeat an operation.

Schedule provides the interval between subsequent invocations, which guarantees that the next operation will start no sooner than the specified duration after the previous operations has finished. If the previous operation takes longer than the interval, the next operation will start immediately after the previous one has finished.

It is a special case of ScheduledConfig with ScheduledConfig.sleepMode always set to SleepMode.Interval and ScheduledConfig.shouldContinueOnError always returning false.

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

schedule

The repeat schedule which determines the maximum number of invocations and the interval between subsequent invocations. See Schedule for more details.

shouldContinueOnResult

A function that determines whether to continue the loop after a success. The function receives the value that was emitted by the last invocation. Defaults to => true.

Attributes

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

Attributes

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

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Schedule

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Schedule.type
case class ScheduledConfig[E, T](schedule: Schedule, onOperationResult: (Int, Either[E, T]) => Unit, shouldContinueOnError: E => Boolean, shouldContinueOnResult: T => Boolean, sleepMode: SleepMode)

A config that defines how to schedule an operation.

A config that defines how to schedule an 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

onOperationResult

A function that is invoked after each invocation. The callback receives the number of the current invocations number (starting from 1) and the result of the operation. The result is either a successful value or an error.

schedule

The schedule which determines the maximum number of invocations and the duration between subsequent invocations. See Schedule for more details.

shouldContinueOnError

A function that determines whether to continue the loop after an error. The function receives the error that was emitted by the last invocation. Defaults to => false.

shouldContinueOnResult

A function that determines whether to continue the loop after a success. The function receives the value that was emitted by the last invocation. Defaults to => true.

sleepMode

The mode that specifies how to interpret the duration provided by the schedule. See SleepMode for more details.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
enum SleepMode

The mode that specifies how to interpret the duration provided by the schedule.

The mode that specifies how to interpret the duration provided by the schedule.

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def repeat[T](config: RepeatConfig[Throwable, T])(operation: => T): T

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

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

repeat is a special case of scheduled with a given set of defaults. See RepeatConfig for more details.

Value parameters

config

The repeat config - see RepeatConfig.

operation

The operation to repeat.

Attributes

Returns

The result of the last invocation if the config decides to stop.

Throws
anything

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

See also
def repeatEither[E, T](config: RepeatConfig[E, T])(operation: => Either[E, T]): Either[E, T]

Repeats an operation returning an scala.util.Either until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the repeat loop.

Repeats an operation returning an scala.util.Either until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the repeat loop.

repeatEither is a special case of scheduledEither with a given set of defaults. See RepeatConfig for more details.

Value parameters

config

The repeat config - see RepeatConfig.

operation

The operation to repeat.

Attributes

Returns

The result of the last invocation if the config decides to stop.

See also
def repeatWithErrorMode[E, F[_], T](em: ErrorMode[E, F])(config: RepeatConfig[E, T])(operation: => F[T]): F[T]

Repeats an operation using the given error mode until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the repeat loop.

Repeats an operation using the given error mode until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the repeat loop.

repeatWithErrorMode is a special case of scheduledWithErrorMode with a given set of defaults. See RepeatConfig for more details.

Value parameters

config

The repeat config - see RepeatConfig.

em

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

operation

The operation to repeat.

Attributes

Returns

The result of the last invocation if the config decides to stop.

See also
def scheduled[T](config: ScheduledConfig[Throwable, T])(operation: => T): T

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

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

Value parameters

config

The repeat config - see ScheduledConfig.

operation

The operation to schedule.

Attributes

Returns

The result of the last invocation if the config decides to stop.

Throws
anything

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

def scheduledEither[E, T](config: ScheduledConfig[E, T])(operation: => Either[E, T]): Either[E, T]

Schedules an operation returning an scala.util.Either until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the schedule loop.

Schedules an operation returning an scala.util.Either until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the schedule loop.

Value parameters

config

The schedule config - see ScheduledConfig.

operation

The operation to schedule.

Attributes

Returns

The result of the last invocation if the config decides to stop.

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

Schedules an operation using the given error mode until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the schedule loop.

Schedules an operation using the given error mode until the config decides to stop. Note that any exceptions thrown by the operation aren't caught and effectively interrupt the schedule loop.

Value parameters

config

The schedule config - see ScheduledConfig.

em

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

operation

The operation to schedule.

Attributes

Returns

The result of the last invocation if the config decides to stop.