All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.codedeploy.waiters.Waiters.kt Maven / Gradle / Ivy

There is a newer version: 1.3.78
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.codedeploy.waiters

import aws.sdk.kotlin.services.codedeploy.CodeDeployClient
import aws.sdk.kotlin.services.codedeploy.model.GetDeploymentRequest
import aws.sdk.kotlin.services.codedeploy.model.GetDeploymentResponse
import aws.smithy.kotlin.runtime.retries.Outcome
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy
import aws.smithy.kotlin.runtime.retries.delay.InfiniteTokenBucket
import aws.smithy.kotlin.runtime.retries.policy.Acceptor
import aws.smithy.kotlin.runtime.retries.policy.AcceptorRetryPolicy
import aws.smithy.kotlin.runtime.retries.policy.OutputAcceptor
import aws.smithy.kotlin.runtime.retries.policy.RetryDirective
import kotlin.time.Duration.Companion.milliseconds


public suspend fun CodeDeployClient.waitUntilDeploymentSuccessful(request: GetDeploymentRequest): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 15_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val deploymentInfo = it.deploymentInfo
            val status = deploymentInfo?.status?.value
            status == "Succeeded"
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val deploymentInfo = it.deploymentInfo
            val status = deploymentInfo?.status?.value
            status == "Failed"
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val deploymentInfo = it.deploymentInfo
            val status = deploymentInfo?.status?.value
            status == "Stopped"
        },
    )

    val policy = AcceptorRetryPolicy(request, acceptors)
    return strategy.retry(policy) { getDeployment(request) }
}

public suspend fun CodeDeployClient.waitUntilDeploymentSuccessful(block: GetDeploymentRequest.Builder.() -> Unit): Outcome =
    waitUntilDeploymentSuccessful(GetDeploymentRequest.Builder().apply(block).build())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy