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

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

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

package aws.sdk.kotlin.services.transfer.waiters

import aws.sdk.kotlin.services.transfer.TransferClient
import aws.sdk.kotlin.services.transfer.model.DescribeServerRequest
import aws.sdk.kotlin.services.transfer.model.DescribeServerResponse
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 TransferClient.waitUntilServerOffline(request: DescribeServerRequest): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 30_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 3_600_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val server = it.server
            val state = server?.state?.value
            state == "OFFLINE"
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val server = it.server
            val state = server?.state?.value
            state == "STOP_FAILED"
        },
    )

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

public suspend fun TransferClient.waitUntilServerOffline(block: DescribeServerRequest.Builder.() -> Unit): Outcome =
    waitUntilServerOffline(DescribeServerRequest.Builder().apply(block).build())

public suspend fun TransferClient.waitUntilServerOnline(request: DescribeServerRequest): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 30_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 3_600_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val server = it.server
            val state = server?.state?.value
            state == "ONLINE"
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val server = it.server
            val state = server?.state?.value
            state == "START_FAILED"
        },
    )

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

public suspend fun TransferClient.waitUntilServerOnline(block: DescribeServerRequest.Builder.() -> Unit): Outcome =
    waitUntilServerOnline(DescribeServerRequest.Builder().apply(block).build())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy