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

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

The newest version!
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.appstream.waiters

import aws.sdk.kotlin.services.appstream.AppStreamClient
import aws.sdk.kotlin.services.appstream.model.DescribeFleetsRequest
import aws.sdk.kotlin.services.appstream.model.DescribeFleetsResponse
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 aws.smithy.kotlin.runtime.util.flattenIfPossible
import kotlin.time.Duration.Companion.milliseconds


public suspend fun AppStreamClient.waitUntilFleetStarted(request: DescribeFleetsRequest = DescribeFleetsRequest { }): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 30_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            !(projection as List).isNullOrEmpty() && projection.all { it == "RUNNING" }
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            (projection as List?)?.any { it == "STOPPING" } ?: false
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            (projection as List?)?.any { it == "STOPPED" } ?: false
        },
    )

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

public suspend fun AppStreamClient.waitUntilFleetStarted(block: DescribeFleetsRequest.Builder.() -> Unit): Outcome =
    waitUntilFleetStarted(DescribeFleetsRequest.Builder().apply(block).build())

public suspend fun AppStreamClient.waitUntilFleetStopped(request: DescribeFleetsRequest = DescribeFleetsRequest { }): Outcome {
    val strategy = StandardRetryStrategy {
        maxAttempts = 20
        tokenBucket = InfiniteTokenBucket
        delayProvider {
            initialDelay = 30_000.milliseconds
            scaleFactor = 1.5
            jitter = 1.0
            maxBackoff = 120_000.milliseconds
        }
    }

    val acceptors = listOf>(
        OutputAcceptor(RetryDirective.TerminateAndSucceed) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            !(projection as List).isNullOrEmpty() && projection.all { it == "STOPPED" }
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            (projection as List?)?.any { it == "STARTING" } ?: false
        },
        OutputAcceptor(RetryDirective.TerminateAndFail) {
            val fleets = it.fleets
            val fleetsOrEmpty = fleets?.flattenIfPossible()
            val projection = fleetsOrEmpty?.flatMap {
                val state = it?.state?.value
                listOfNotNull(state)
            }
            (projection as List?)?.any { it == "RUNNING" } ?: false
        },
    )

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

public suspend fun AppStreamClient.waitUntilFleetStopped(block: DescribeFleetsRequest.Builder.() -> Unit): Outcome =
    waitUntilFleetStopped(DescribeFleetsRequest.Builder().apply(block).build())




© 2015 - 2025 Weber Informatics LLC | Privacy Policy