in magenta-lib/src/main/scala/magenta/tasks/gcp/GCPRetryHelper.scala [83:123]
private def retryInternal[T](
reporter: DeployReporter,
backoffIntervals: Seq[FiniteDuration],
pred: Predicate[Throwable],
failureLogMessage: String
)(op: => Result[T]): Retryable[T] = {
def loop(
remainingBackoffIntervals: Seq[FiniteDuration],
errors: => List[Throwable]
): Retryable[T] = {
op match {
case Right(x) => Right((errors, x))
case Left(t) if pred(t) && remainingBackoffIntervals.nonEmpty =>
log(
reporter,
s"$failureLogMessage: ${remainingBackoffIntervals.size} retries remaining, retrying in ${remainingBackoffIntervals.head}",
t
)
after(remainingBackoffIntervals.head) {
loop(remainingBackoffIntervals.tail, t :: errors)
}
case Left(t) =>
if (remainingBackoffIntervals.isEmpty) {
log(reporter, s"$failureLogMessage: no retries remaining", t)
} else {
log(
reporter,
s"$failureLogMessage: retries remain but predicate failed, not retrying",
t
)
}
Left(NonEmptyList(t, errors))
}
}
loop(backoffIntervals, List.empty)
}