Skip to content

Commit

Permalink
Fix azure retry policy
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Jan 8, 2024
1 parent 1b72d99 commit 03a58fa
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java.math.RoundingMode
import java.nio.file.Path
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.concurrent.TimeoutException
import java.util.function.Predicate

import com.microsoft.azure.batch.BatchClient
Expand Down Expand Up @@ -912,8 +913,22 @@ class AzBatchService implements Closeable {
* @return The result of the supplied action
*/
protected <T> T apply(CheckedSupplier<T> action) {
final cond = (e -> e instanceof BatchErrorException && e.body().code() in RETRY_CODES) as Predicate<? extends Throwable>
// define the retry condition
final cond = new Predicate<? extends Throwable>() {
@Override
boolean test(Throwable t) {
if( t instanceof BatchErrorException && t.body().code() in RETRY_CODES )
return true
if( t instanceof IOException || t.cause instanceof IOException )
return true
if( t instanceof TimeoutException || t.cause instanceof TimeoutException )
return true
return false
}
}
// create the retry policy object
final policy = retryPolicy(cond)
// apply the action with
return Failsafe.with(policy).get(action)
}
}

0 comments on commit 03a58fa

Please sign in to comment.