Retry

class Retry(val attempts: Int = 3, val pause: Duration = 1.seconds, val factor: Double = 2.0, val maxPause: Duration = 30.seconds, val retryOn: (Throwable) -> Boolean = { true })

Says how often a node is tried again after it failed, and how long the engine waits between two tries. Give it to a node as retry:

val fetch = node("fetch", retry = Retry(attempts = 3)) { order ->
order.copy(stock = warehouse.stock(order.item))
}

A node that fails runs again on the same state, in the same step, until it succeeds or has run attempts times. Then the run fails with a NodeExecutionException, as it does without a retry. The engine waits pause before the second try, and factor times longer before each try after it, but never longer than maxPause: with the defaults 1 second, then 2, then 4.

Every failure of the node is retried, also a time limit of the node that ran out, with one exception: a GraphValidationException is not, because a second try would fail in the same way. To retry only some failures, pass retryOn:

Retry(attempts = 3) { failure -> failure is IOException }

What is no failure of a node is never retried: a cancelled run, a pause with interrupt, and an error of the program such as an AssertionError.

A node with a retry runs more than once, so make its side effects safe to repeat.

Throws

if attempts is less than 1, pause or maxPause is negative, or factor is less than 1.

Constructors

Link copied to clipboard
constructor(attempts: Int = 3, pause: Duration = 1.seconds, factor: Double = 2.0, maxPause: Duration = 30.seconds, retryOn: (Throwable) -> Boolean = { true })

Properties

Link copied to clipboard

how often the node runs at most, with its first try.

Link copied to clipboard

what the pause is multiplied by after each try.

Link copied to clipboard

the longest pause between two tries.

Link copied to clipboard

how long the engine waits before the second try.

Link copied to clipboard

returns true for a failure that is worth another try. It gets what the node threw.

Functions

Link copied to clipboard
open override fun toString(): String