Closed yawaramin closed 6 years ago
One possible way to do this is to redefine ExecutionPlan#retryStrategy
to be a stream of retry descriptions (Retry
objects); we retry as long as there are more elements in the stream, obeying the described interval. Then the exponential backoff strategy could be something like
object Retry {
/**
Returns a stream of retry descriptions following the exponential backoff strategy.
*/
def exponentialBackoff(initialInterval: FiniteDuration, increaseFactor: Int, attempts: Int) =
Stream.iterate(Retry(initialInterval), attempts) { retry =>
retry.copy(interval = increaseFactor * retry.interval)
}
val noRetry = Stream.empty
}
Of course, with this re-definition of ExecutionPlan#retryStrategy
, the implication is that Retry#attempts
is no longer needed and a retry description becomes semantically just an interval to wait: case class Retry(interval: FiniteDuration) extends AnyVal
. The number of attempts is captured by the length of the retry strategy stream.
com.mediative.eigenflow.domain.Retry
type which implements potential retry strategies