in core/src/main/scala/org/apache/pekko/persistence/cassandra/Retries.scala [41:70]
private def retry[T](
attempt: () => Future[T],
maxAttempts: Int,
onFailure: (Int, Throwable, FiniteDuration) => Unit,
minBackoff: FiniteDuration,
maxBackoff: FiniteDuration,
randomFactor: Double,
attempted: Int)(implicit ec: ExecutionContext, scheduler: Scheduler): Future[T] = {
def tryAttempt(): Future[T] = {
try {
attempt()
} catch {
case NonFatal(exc) => Future.failed(exc) // in case the `attempt` function throws
}
}
if (maxAttempts == -1 || maxAttempts - attempted != 1) {
tryAttempt().recoverWith {
case NonFatal(exc) =>
val nextDelay = BackoffSupervisor.calculateDelay(attempted, minBackoff, maxBackoff, randomFactor)
onFailure(attempted + 1, exc, nextDelay)
after(nextDelay, scheduler) {
retry(attempt, maxAttempts, onFailure, minBackoff, maxBackoff, randomFactor, attempted + 1)
}
}
} else {
tryAttempt()
}
}