Skip to content

Commit

Permalink
applied suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterITA committed Jul 1, 2024
1 parent a663350 commit 524996c
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,24 @@ object Utils {
def pollEServiceById(
fetchFunc: => Future[CatalogProcess.EService],
condition: CatalogProcess.EService => Boolean,
maxRetries: Int = 10,
maxRetries: Int = 30,
delay: FiniteDuration = 200.millis
)(implicit ec: ExecutionContext): Future[Unit] = {

def poll(attempt: Int): Future[Unit] = {
if (attempt > maxRetries) {
Future.failed(new RuntimeException("Max retries reached"))
} else {
fetchFunc.flatMap { result =>
if (condition(result)) {
Future.successful(())
} else {
Future { Thread.sleep(delay.millis) }.flatMap(_ => poll(attempt + 1))
fetchFunc
.flatMap { result =>
if (condition(result)) {
Future.successful(())
} else {
Future { Thread.sleep(delay.toMillis) }.flatMap(_ => poll(attempt + 1))
}
}
}
.recoverWith { case _ => Future { Thread.sleep(delay.toMillis) }.flatMap(_ => poll(attempt + 1)) }

}
}

Expand Down

0 comments on commit 524996c

Please sign in to comment.