Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retryStrategy configuration option for waiters #1183

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changes/0857b6f0-0444-479f-be6b-06ef71d482a0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "0857b6f0-0444-479f-be6b-06ef71d482a0",
"type": "feature",
"description": "⚠️ **IMPORTANT**: Add `retryStrategy` configuration option for waiters",
"issues": [
"https://github.com/awslabs/aws-sdk-kotlin/issues/1431"
],
"requiresMinorVersionBump": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.text.DecimalFormatSymbols
* Renders the top-level retry strategy for a waiter.
*/
private fun KotlinWriter.renderRetryStrategy(wi: WaiterInfo, asValName: String) {
withBlock("val #L = #T {", "}", asValName, RuntimeTypes.Core.Retries.StandardRetryStrategy) {
withBlock("val #L = retryStrategy ?: #T {", "}", asValName, RuntimeTypes.Core.Retries.StandardRetryStrategy) {
write("maxAttempts = 20")
write("tokenBucket = #T", RuntimeTypes.Core.Retries.Delay.InfiniteTokenBucket)
withBlock("delayProvider {", "}") {
Expand All @@ -35,18 +35,21 @@ private fun KotlinWriter.renderRetryStrategy(wi: WaiterInfo, asValName: String)
internal fun KotlinWriter.renderWaiter(wi: WaiterInfo) {
write("")
wi.waiter.documentation.ifPresent(::dokka)
val inputParameter = if (wi.input.hasAllOptionalMembers) {
format("request: #1T = #1T { }", wi.inputSymbol)

val requestType = if (wi.input.hasAllOptionalMembers) {
format("#1T = #1T { }", wi.inputSymbol)
} else {
format("request: #T", wi.inputSymbol)
format("#T", wi.inputSymbol)
}

withBlock(
"#L suspend fun #T.#L(#L): #T<#T> {",
"#L suspend fun #T.#L(request: #L, retryStrategy: #T? = null): #T<#T> {",
"}",
wi.ctx.settings.api.visibility,
wi.serviceSymbol,
wi.methodName,
inputParameter,
requestType,
RuntimeTypes.Core.Retries.RetryStrategy,
RuntimeTypes.Core.Retries.Outcome,
wi.outputSymbol,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ServiceWaitersGeneratorTest {
/**
* Wait until a foo exists with optional input
*/
public suspend fun TestClient.waitUntilFooOptionalExists(request: DescribeFooOptionalRequest = DescribeFooOptionalRequest { }): Outcome<DescribeFooOptionalResponse> {
public suspend fun TestClient.waitUntilFooOptionalExists(request: DescribeFooOptionalRequest = DescribeFooOptionalRequest { }, retryStrategy: RetryStrategy? = null): Outcome<DescribeFooOptionalResponse> {
""".trimIndent()
val methodFooter = """
val policy = AcceptorRetryPolicy(request, acceptors)
Expand All @@ -59,7 +59,7 @@ class ServiceWaitersGeneratorTest {
/**
* Wait until a foo exists with required input
*/
public suspend fun TestClient.waitUntilFooRequiredExists(request: DescribeFooRequiredRequest): Outcome<DescribeFooRequiredResponse> {
public suspend fun TestClient.waitUntilFooRequiredExists(request: DescribeFooRequiredRequest, retryStrategy: RetryStrategy? = null): Outcome<DescribeFooRequiredResponse> {
""".trimIndent()
listOf(
generateService("simple-service-with-operation-waiter.smithy"),
Expand Down Expand Up @@ -105,7 +105,7 @@ class ServiceWaitersGeneratorTest {
@Test
fun testRetryStrategy() {
val expected = """
val strategy = StandardRetryStrategy {
val strategy = retryStrategy ?: StandardRetryStrategy {
maxAttempts = 20
tokenBucket = InfiniteTokenBucket
delayProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WaiterGeneratorTest {
@Test
fun testDefaultDelays() {
val expected = """
val strategy = StandardRetryStrategy {
val strategy = retryStrategy ?: StandardRetryStrategy {
maxAttempts = 20
tokenBucket = InfiniteTokenBucket
delayProvider {
Expand All @@ -45,7 +45,7 @@ class WaiterGeneratorTest {
@Test
fun testCustomDelays() {
val expected = """
val strategy = StandardRetryStrategy {
val strategy = retryStrategy ?: StandardRetryStrategy {
maxAttempts = 20
tokenBucket = InfiniteTokenBucket
delayProvider {
Expand Down
Loading