currently, I want to wrap my WsClient inside a Akka backoff. for failure testing, we tried both Http 404 and timeout. when the error happened caused by Http 404, the backoff worked normally. But when it encountered a WsClient timeout, it keep restarting forever without any exponential backoff or maximum restart time. bellow is part of my code
RestartSource.onFailuresWithBackoff(
minBackoff = 1 seconds,
maxBackoff = 20 seconds,
randomFactor = 1,
maxRestarts = 10
) { () =>
val futureResult: Future[Any] = myMethod()
Source.future(futureResult)
.map {
case Failure =>
throw new RuntimeException("testing BackOff")
case Success =>
log.info("FINISH")
case _ => log.info("else")
}
}.runWith(Sink.head)
.recoverWith {
case _ =>
log.info("exceed retries")
)
}.foreach(println)
private def myMethod(): Future[Any] = {
val inquiryRequest = xxx
wsClient.url(url)
.withRequestTimeout(1 seconds)
.post(Json.toJson(inquiryRequest).toString)
.flatMap { pureResult =>
Status.Success
}.recover { e =>
log.error("test")
Status.Failure
}
}