Skip to content

Commit 47ad099

Browse files
committed
Add retryStrategy configuration option for waiters
1 parent 1d3028e commit 47ad099

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/waiters/WaiterGenerator.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.text.DecimalFormatSymbols
1717
* Renders the top-level retry strategy for a waiter.
1818
*/
1919
private fun KotlinWriter.renderRetryStrategy(wi: WaiterInfo, asValName: String) {
20-
withBlock("val #L = #T {", "}", asValName, RuntimeTypes.Core.Retries.StandardRetryStrategy) {
20+
withBlock("val #L = retryStrategy ?: #T {", "}", asValName, RuntimeTypes.Core.Retries.StandardRetryStrategy) {
2121
write("maxAttempts = 20")
2222
write("tokenBucket = #T", RuntimeTypes.Core.Retries.Delay.InfiniteTokenBucket)
2323
withBlock("delayProvider {", "}") {
@@ -35,18 +35,21 @@ private fun KotlinWriter.renderRetryStrategy(wi: WaiterInfo, asValName: String)
3535
internal fun KotlinWriter.renderWaiter(wi: WaiterInfo) {
3636
write("")
3737
wi.waiter.documentation.ifPresent(::dokka)
38-
val inputParameter = if (wi.input.hasAllOptionalMembers) {
39-
format("request: #1T = #1T { }", wi.inputSymbol)
38+
39+
val requestType = if (wi.input.hasAllOptionalMembers) {
40+
format("#1T = #1T { }", wi.inputSymbol)
4041
} else {
41-
format("request: #T", wi.inputSymbol)
42+
format("#T", wi.inputSymbol)
4243
}
44+
4345
withBlock(
44-
"#L suspend fun #T.#L(#L): #T<#T> {",
46+
"#L suspend fun #T.#L(request: #L, retryStrategy: #T? = null): #T<#T> {",
4547
"}",
4648
wi.ctx.settings.api.visibility,
4749
wi.serviceSymbol,
4850
wi.methodName,
49-
inputParameter,
51+
requestType,
52+
RuntimeTypes.Core.Retries.RetryStrategy,
5053
RuntimeTypes.Core.Retries.Outcome,
5154
wi.outputSymbol,
5255
) {

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/waiters/ServiceWaitersGeneratorTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ServiceWaitersGeneratorTest {
4343
/**
4444
* Wait until a foo exists with optional input
4545
*/
46-
public suspend fun TestClient.waitUntilFooOptionalExists(request: DescribeFooOptionalRequest = DescribeFooOptionalRequest { }): Outcome<DescribeFooOptionalResponse> {
46+
public suspend fun TestClient.waitUntilFooOptionalExists(request: DescribeFooOptionalRequest = DescribeFooOptionalRequest { }, retryStrategy: RetryStrategy? = null): Outcome<DescribeFooOptionalResponse> {
4747
""".trimIndent()
4848
val methodFooter = """
4949
val policy = AcceptorRetryPolicy(request, acceptors)
@@ -59,7 +59,7 @@ class ServiceWaitersGeneratorTest {
5959
/**
6060
* Wait until a foo exists with required input
6161
*/
62-
public suspend fun TestClient.waitUntilFooRequiredExists(request: DescribeFooRequiredRequest): Outcome<DescribeFooRequiredResponse> {
62+
public suspend fun TestClient.waitUntilFooRequiredExists(request: DescribeFooRequiredRequest, retryStrategy: RetryStrategy? = null): Outcome<DescribeFooRequiredResponse> {
6363
""".trimIndent()
6464
listOf(
6565
generateService("simple-service-with-operation-waiter.smithy"),
@@ -105,7 +105,7 @@ class ServiceWaitersGeneratorTest {
105105
@Test
106106
fun testRetryStrategy() {
107107
val expected = """
108-
val strategy = StandardRetryStrategy {
108+
val strategy = retryStrategy ?: StandardRetryStrategy {
109109
maxAttempts = 20
110110
tokenBucket = InfiniteTokenBucket
111111
delayProvider {

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/waiters/WaiterGeneratorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class WaiterGeneratorTest {
2828
@Test
2929
fun testDefaultDelays() {
3030
val expected = """
31-
val strategy = StandardRetryStrategy {
31+
val strategy = retryStrategy ?: StandardRetryStrategy {
3232
maxAttempts = 20
3333
tokenBucket = InfiniteTokenBucket
3434
delayProvider {
@@ -45,7 +45,7 @@ class WaiterGeneratorTest {
4545
@Test
4646
fun testCustomDelays() {
4747
val expected = """
48-
val strategy = StandardRetryStrategy {
48+
val strategy = retryStrategy ?: StandardRetryStrategy {
4949
maxAttempts = 20
5050
tokenBucket = InfiniteTokenBucket
5151
delayProvider {

0 commit comments

Comments
 (0)