-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exporting cloud watch logs has a quota, 1 task per account. requiring a retry if the limit is exceeded.
- Loading branch information
Showing
6 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ess-substrate-aws-common/src/main/java/clusterless/cls/substrate/aws/sdk/ClientRetry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2023 Chris K Wensel <[email protected]>. All Rights Reserved. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package clusterless.cls.substrate.aws.sdk; | ||
|
||
import io.github.resilience4j.core.IntervalFunction; | ||
import io.github.resilience4j.retry.Retry; | ||
import io.github.resilience4j.retry.RetryConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.awssdk.awscore.AwsClient; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class ClientRetry<C extends AwsClient> { | ||
private static final Logger LOG = LoggerFactory.getLogger(ClientRetry.class); | ||
private final RetryConfig config; | ||
private final String client; | ||
|
||
public ClientRetry(String client, int maxAttempts, Predicate<ClientBase<C>.Response> predicate) { | ||
this.client = client; | ||
this.config = RetryConfig.<ClientBase<C>.Response>custom() | ||
.maxAttempts(maxAttempts) | ||
.intervalFunction(IntervalFunction.ofExponentialBackoff(Duration.ofSeconds(30), 2.0, Duration.ofMinutes(5))) | ||
.consumeResultBeforeRetryAttempt((attempt, response) -> LOG.warn("got: {}, for retry attempt: {} of {}", response.errorMessage(), attempt, maxAttempts)) | ||
.retryOnResult(predicate) | ||
.failAfterMaxAttempts(true) | ||
.build(); | ||
} | ||
|
||
public ClientBase<C>.Response invoke(Supplier<ClientBase<C>.Response> checkedSupplier) { | ||
return Retry.of(client, config) | ||
.executeSupplier(checkedSupplier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters