commonMain.aws.sdk.kotlin.runtime.config.retries.ResolveRetryStrategy.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-config-jvm Show documentation
Show all versions of aws-config-jvm Show documentation
Support for AWS configuration
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.runtime.config.retries
import aws.sdk.kotlin.runtime.ConfigurationException
import aws.sdk.kotlin.runtime.InternalSdkApi
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.config.profile.maxAttempts
import aws.sdk.kotlin.runtime.config.profile.retryMode
import aws.smithy.kotlin.runtime.client.config.RetryMode
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.retries.AdaptiveRetryStrategy
import aws.smithy.kotlin.runtime.retries.RetryStrategy
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider
import aws.smithy.kotlin.runtime.util.asyncLazy
/**
* Attempt to resolve the retry strategy used to make requests by fetching the max attempts and retry mode. Currently,
* we only support the legacy and standard retry modes.
*/
@InternalSdkApi
public suspend fun resolveRetryStrategy(
platformProvider: PlatformProvider = PlatformProvider.System,
profile: LazyAsyncValue = asyncLazy { loadAwsSharedConfig(platformProvider).activeProfile },
): RetryStrategy {
val maxAttempts = AwsSdkSetting.AwsMaxAttempts.resolve(platformProvider)
?: profile.get().maxAttempts
val retryMode = AwsSdkSetting.AwsRetryMode.resolve(platformProvider)
?: profile.get().retryMode
?: RetryMode.STANDARD
val factory = when (retryMode) {
RetryMode.STANDARD, RetryMode.LEGACY -> StandardRetryStrategy
RetryMode.ADAPTIVE -> AdaptiveRetryStrategy
}
return factory {
maxAttempts?.let {
if (it < 1) {
throw ConfigurationException("max attempts was $it, but should be at least 1")
}
this.maxAttempts = it
}
}
}