1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package lexmodelsv2 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithytime "github.com/aws/smithy-go/time" 13 smithyhttp "github.com/aws/smithy-go/transport/http" 14 smithywaiter "github.com/aws/smithy-go/waiter" 15 "github.com/jmespath/go-jmespath" 16 "time" 17) 18 19// Describes the settings that a bot has for a specific locale. 20func (c *Client) DescribeBotLocale(ctx context.Context, params *DescribeBotLocaleInput, optFns ...func(*Options)) (*DescribeBotLocaleOutput, error) { 21 if params == nil { 22 params = &DescribeBotLocaleInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "DescribeBotLocale", params, optFns, c.addOperationDescribeBotLocaleMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*DescribeBotLocaleOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type DescribeBotLocaleInput struct { 36 37 // The identifier of the bot associated with the locale. 38 // 39 // This member is required. 40 BotId *string 41 42 // The identifier of the version of the bot associated with the locale. 43 // 44 // This member is required. 45 BotVersion *string 46 47 // The unique identifier of the locale to describe. The string must match one of 48 // the supported locales. For more information, see Supported languages 49 // (https://docs.aws.amazon.com/lexv2/latest/dg/how-languages.html). 50 // 51 // This member is required. 52 LocaleId *string 53 54 noSmithyDocumentSerde 55} 56 57type DescribeBotLocaleOutput struct { 58 59 // The identifier of the bot associated with the locale. 60 BotId *string 61 62 // History of changes, such as when a locale is used in an alias, that have taken 63 // place for the locale. 64 BotLocaleHistoryEvents []types.BotLocaleHistoryEvent 65 66 // The status of the bot. If the status is Failed, the reasons for the failure are 67 // listed in the failureReasons field. 68 BotLocaleStatus types.BotLocaleStatus 69 70 // The identifier of the version of the bot associated with the locale. 71 BotVersion *string 72 73 // The date and time that the locale was created. 74 CreationDateTime *time.Time 75 76 // The description of the locale. 77 Description *string 78 79 // if botLocaleStatus is Failed, Amazon Lex explains why it failed to build the 80 // bot. 81 FailureReasons []string 82 83 // The number of intents defined for the locale. 84 IntentsCount *int32 85 86 // The date and time that the locale was last submitted for building. 87 LastBuildSubmittedDateTime *time.Time 88 89 // The date and time that the locale was last updated. 90 LastUpdatedDateTime *time.Time 91 92 // The unique identifier of the described locale. 93 LocaleId *string 94 95 // The name of the locale. 96 LocaleName *string 97 98 // The confidence threshold where Amazon Lex inserts the AMAZON.FallbackIntent and 99 // AMAZON.KendraSearchIntent intents in the list of possible intents for an 100 // utterance. 101 NluIntentConfidenceThreshold *float64 102 103 // The number of slot types defined for the locale. 104 SlotTypesCount *int32 105 106 // The Amazon Polly voice Amazon Lex uses for voice interaction with the user. 107 VoiceSettings *types.VoiceSettings 108 109 // Metadata pertaining to the operation's result. 110 ResultMetadata middleware.Metadata 111 112 noSmithyDocumentSerde 113} 114 115func (c *Client) addOperationDescribeBotLocaleMiddlewares(stack *middleware.Stack, options Options) (err error) { 116 err = stack.Serialize.Add(&awsRestjson1_serializeOpDescribeBotLocale{}, middleware.After) 117 if err != nil { 118 return err 119 } 120 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDescribeBotLocale{}, middleware.After) 121 if err != nil { 122 return err 123 } 124 if err = addSetLoggerMiddleware(stack, options); err != nil { 125 return err 126 } 127 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 128 return err 129 } 130 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 131 return err 132 } 133 if err = addResolveEndpointMiddleware(stack, options); err != nil { 134 return err 135 } 136 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 137 return err 138 } 139 if err = addRetryMiddlewares(stack, options); err != nil { 140 return err 141 } 142 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 143 return err 144 } 145 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 146 return err 147 } 148 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 149 return err 150 } 151 if err = addClientUserAgent(stack); err != nil { 152 return err 153 } 154 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 155 return err 156 } 157 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 158 return err 159 } 160 if err = addOpDescribeBotLocaleValidationMiddleware(stack); err != nil { 161 return err 162 } 163 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeBotLocale(options.Region), middleware.Before); err != nil { 164 return err 165 } 166 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 167 return err 168 } 169 if err = addResponseErrorMiddleware(stack); err != nil { 170 return err 171 } 172 if err = addRequestResponseLogging(stack, options); err != nil { 173 return err 174 } 175 return nil 176} 177 178// DescribeBotLocaleAPIClient is a client that implements the DescribeBotLocale 179// operation. 180type DescribeBotLocaleAPIClient interface { 181 DescribeBotLocale(context.Context, *DescribeBotLocaleInput, ...func(*Options)) (*DescribeBotLocaleOutput, error) 182} 183 184var _ DescribeBotLocaleAPIClient = (*Client)(nil) 185 186// BotLocaleBuiltWaiterOptions are waiter options for BotLocaleBuiltWaiter 187type BotLocaleBuiltWaiterOptions struct { 188 189 // Set of options to modify how an operation is invoked. These apply to all 190 // operations invoked for this client. Use functional options on operation call to 191 // modify this list for per operation behavior. 192 APIOptions []func(*middleware.Stack) error 193 194 // MinDelay is the minimum amount of time to delay between retries. If unset, 195 // BotLocaleBuiltWaiter will use default minimum delay of 10 seconds. Note that 196 // MinDelay must resolve to a value lesser than or equal to the MaxDelay. 197 MinDelay time.Duration 198 199 // MaxDelay is the maximum amount of time to delay between retries. If unset or set 200 // to zero, BotLocaleBuiltWaiter will use default max delay of 120 seconds. Note 201 // that MaxDelay must resolve to value greater than or equal to the MinDelay. 202 MaxDelay time.Duration 203 204 // LogWaitAttempts is used to enable logging for waiter retry attempts 205 LogWaitAttempts bool 206 207 // Retryable is function that can be used to override the service defined 208 // waiter-behavior based on operation output, or returned error. This function is 209 // used by the waiter to decide if a state is retryable or a terminal state. By 210 // default service-modeled logic will populate this option. This option can thus be 211 // used to define a custom waiter state with fall-back to service-modeled waiter 212 // state mutators.The function returns an error in case of a failure state. In case 213 // of retry state, this function returns a bool value of true and nil error, while 214 // in case of success it returns a bool value of false and nil error. 215 Retryable func(context.Context, *DescribeBotLocaleInput, *DescribeBotLocaleOutput, error) (bool, error) 216} 217 218// BotLocaleBuiltWaiter defines the waiters for BotLocaleBuilt 219type BotLocaleBuiltWaiter struct { 220 client DescribeBotLocaleAPIClient 221 222 options BotLocaleBuiltWaiterOptions 223} 224 225// NewBotLocaleBuiltWaiter constructs a BotLocaleBuiltWaiter. 226func NewBotLocaleBuiltWaiter(client DescribeBotLocaleAPIClient, optFns ...func(*BotLocaleBuiltWaiterOptions)) *BotLocaleBuiltWaiter { 227 options := BotLocaleBuiltWaiterOptions{} 228 options.MinDelay = 10 * time.Second 229 options.MaxDelay = 120 * time.Second 230 options.Retryable = botLocaleBuiltStateRetryable 231 232 for _, fn := range optFns { 233 fn(&options) 234 } 235 return &BotLocaleBuiltWaiter{ 236 client: client, 237 options: options, 238 } 239} 240 241// Wait calls the waiter function for BotLocaleBuilt waiter. The maxWaitDur is the 242// maximum wait duration the waiter will wait. The maxWaitDur is required and must 243// be greater than zero. 244func (w *BotLocaleBuiltWaiter) Wait(ctx context.Context, params *DescribeBotLocaleInput, maxWaitDur time.Duration, optFns ...func(*BotLocaleBuiltWaiterOptions)) error { 245 if maxWaitDur <= 0 { 246 return fmt.Errorf("maximum wait time for waiter must be greater than zero") 247 } 248 249 options := w.options 250 for _, fn := range optFns { 251 fn(&options) 252 } 253 254 if options.MaxDelay <= 0 { 255 options.MaxDelay = 120 * time.Second 256 } 257 258 if options.MinDelay > options.MaxDelay { 259 return fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) 260 } 261 262 ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) 263 defer cancelFn() 264 265 logger := smithywaiter.Logger{} 266 remainingTime := maxWaitDur 267 268 var attempt int64 269 for { 270 271 attempt++ 272 apiOptions := options.APIOptions 273 start := time.Now() 274 275 if options.LogWaitAttempts { 276 logger.Attempt = attempt 277 apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) 278 apiOptions = append(apiOptions, logger.AddLogger) 279 } 280 281 out, err := w.client.DescribeBotLocale(ctx, params, func(o *Options) { 282 o.APIOptions = append(o.APIOptions, apiOptions...) 283 }) 284 285 retryable, err := options.Retryable(ctx, params, out, err) 286 if err != nil { 287 return err 288 } 289 if !retryable { 290 return nil 291 } 292 293 remainingTime -= time.Since(start) 294 if remainingTime < options.MinDelay || remainingTime <= 0 { 295 break 296 } 297 298 // compute exponential backoff between waiter retries 299 delay, err := smithywaiter.ComputeDelay( 300 attempt, options.MinDelay, options.MaxDelay, remainingTime, 301 ) 302 if err != nil { 303 return fmt.Errorf("error computing waiter delay, %w", err) 304 } 305 306 remainingTime -= delay 307 // sleep for the delay amount before invoking a request 308 if err := smithytime.SleepWithContext(ctx, delay); err != nil { 309 return fmt.Errorf("request cancelled while waiting, %w", err) 310 } 311 } 312 return fmt.Errorf("exceeded max wait time for BotLocaleBuilt waiter") 313} 314 315func botLocaleBuiltStateRetryable(ctx context.Context, input *DescribeBotLocaleInput, output *DescribeBotLocaleOutput, err error) (bool, error) { 316 317 if err == nil { 318 pathValue, err := jmespath.Search("botLocaleStatus", output) 319 if err != nil { 320 return false, fmt.Errorf("error evaluating waiter state: %w", err) 321 } 322 323 expectedValue := "Built" 324 value, ok := pathValue.(types.BotLocaleStatus) 325 if !ok { 326 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 327 } 328 329 if string(value) == expectedValue { 330 return false, nil 331 } 332 } 333 334 if err == nil { 335 pathValue, err := jmespath.Search("botLocaleStatus", output) 336 if err != nil { 337 return false, fmt.Errorf("error evaluating waiter state: %w", err) 338 } 339 340 expectedValue := "Deleting" 341 value, ok := pathValue.(types.BotLocaleStatus) 342 if !ok { 343 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 344 } 345 346 if string(value) == expectedValue { 347 return false, fmt.Errorf("waiter state transitioned to Failure") 348 } 349 } 350 351 if err == nil { 352 pathValue, err := jmespath.Search("botLocaleStatus", output) 353 if err != nil { 354 return false, fmt.Errorf("error evaluating waiter state: %w", err) 355 } 356 357 expectedValue := "Failed" 358 value, ok := pathValue.(types.BotLocaleStatus) 359 if !ok { 360 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 361 } 362 363 if string(value) == expectedValue { 364 return false, fmt.Errorf("waiter state transitioned to Failure") 365 } 366 } 367 368 if err == nil { 369 pathValue, err := jmespath.Search("botLocaleStatus", output) 370 if err != nil { 371 return false, fmt.Errorf("error evaluating waiter state: %w", err) 372 } 373 374 expectedValue := "NotBuilt" 375 value, ok := pathValue.(types.BotLocaleStatus) 376 if !ok { 377 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 378 } 379 380 if string(value) == expectedValue { 381 return false, fmt.Errorf("waiter state transitioned to Failure") 382 } 383 } 384 385 return true, nil 386} 387 388// BotLocaleCreatedWaiterOptions are waiter options for BotLocaleCreatedWaiter 389type BotLocaleCreatedWaiterOptions struct { 390 391 // Set of options to modify how an operation is invoked. These apply to all 392 // operations invoked for this client. Use functional options on operation call to 393 // modify this list for per operation behavior. 394 APIOptions []func(*middleware.Stack) error 395 396 // MinDelay is the minimum amount of time to delay between retries. If unset, 397 // BotLocaleCreatedWaiter will use default minimum delay of 10 seconds. Note that 398 // MinDelay must resolve to a value lesser than or equal to the MaxDelay. 399 MinDelay time.Duration 400 401 // MaxDelay is the maximum amount of time to delay between retries. If unset or set 402 // to zero, BotLocaleCreatedWaiter will use default max delay of 120 seconds. Note 403 // that MaxDelay must resolve to value greater than or equal to the MinDelay. 404 MaxDelay time.Duration 405 406 // LogWaitAttempts is used to enable logging for waiter retry attempts 407 LogWaitAttempts bool 408 409 // Retryable is function that can be used to override the service defined 410 // waiter-behavior based on operation output, or returned error. This function is 411 // used by the waiter to decide if a state is retryable or a terminal state. By 412 // default service-modeled logic will populate this option. This option can thus be 413 // used to define a custom waiter state with fall-back to service-modeled waiter 414 // state mutators.The function returns an error in case of a failure state. In case 415 // of retry state, this function returns a bool value of true and nil error, while 416 // in case of success it returns a bool value of false and nil error. 417 Retryable func(context.Context, *DescribeBotLocaleInput, *DescribeBotLocaleOutput, error) (bool, error) 418} 419 420// BotLocaleCreatedWaiter defines the waiters for BotLocaleCreated 421type BotLocaleCreatedWaiter struct { 422 client DescribeBotLocaleAPIClient 423 424 options BotLocaleCreatedWaiterOptions 425} 426 427// NewBotLocaleCreatedWaiter constructs a BotLocaleCreatedWaiter. 428func NewBotLocaleCreatedWaiter(client DescribeBotLocaleAPIClient, optFns ...func(*BotLocaleCreatedWaiterOptions)) *BotLocaleCreatedWaiter { 429 options := BotLocaleCreatedWaiterOptions{} 430 options.MinDelay = 10 * time.Second 431 options.MaxDelay = 120 * time.Second 432 options.Retryable = botLocaleCreatedStateRetryable 433 434 for _, fn := range optFns { 435 fn(&options) 436 } 437 return &BotLocaleCreatedWaiter{ 438 client: client, 439 options: options, 440 } 441} 442 443// Wait calls the waiter function for BotLocaleCreated waiter. The maxWaitDur is 444// the maximum wait duration the waiter will wait. The maxWaitDur is required and 445// must be greater than zero. 446func (w *BotLocaleCreatedWaiter) Wait(ctx context.Context, params *DescribeBotLocaleInput, maxWaitDur time.Duration, optFns ...func(*BotLocaleCreatedWaiterOptions)) error { 447 if maxWaitDur <= 0 { 448 return fmt.Errorf("maximum wait time for waiter must be greater than zero") 449 } 450 451 options := w.options 452 for _, fn := range optFns { 453 fn(&options) 454 } 455 456 if options.MaxDelay <= 0 { 457 options.MaxDelay = 120 * time.Second 458 } 459 460 if options.MinDelay > options.MaxDelay { 461 return fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) 462 } 463 464 ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) 465 defer cancelFn() 466 467 logger := smithywaiter.Logger{} 468 remainingTime := maxWaitDur 469 470 var attempt int64 471 for { 472 473 attempt++ 474 apiOptions := options.APIOptions 475 start := time.Now() 476 477 if options.LogWaitAttempts { 478 logger.Attempt = attempt 479 apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) 480 apiOptions = append(apiOptions, logger.AddLogger) 481 } 482 483 out, err := w.client.DescribeBotLocale(ctx, params, func(o *Options) { 484 o.APIOptions = append(o.APIOptions, apiOptions...) 485 }) 486 487 retryable, err := options.Retryable(ctx, params, out, err) 488 if err != nil { 489 return err 490 } 491 if !retryable { 492 return nil 493 } 494 495 remainingTime -= time.Since(start) 496 if remainingTime < options.MinDelay || remainingTime <= 0 { 497 break 498 } 499 500 // compute exponential backoff between waiter retries 501 delay, err := smithywaiter.ComputeDelay( 502 attempt, options.MinDelay, options.MaxDelay, remainingTime, 503 ) 504 if err != nil { 505 return fmt.Errorf("error computing waiter delay, %w", err) 506 } 507 508 remainingTime -= delay 509 // sleep for the delay amount before invoking a request 510 if err := smithytime.SleepWithContext(ctx, delay); err != nil { 511 return fmt.Errorf("request cancelled while waiting, %w", err) 512 } 513 } 514 return fmt.Errorf("exceeded max wait time for BotLocaleCreated waiter") 515} 516 517func botLocaleCreatedStateRetryable(ctx context.Context, input *DescribeBotLocaleInput, output *DescribeBotLocaleOutput, err error) (bool, error) { 518 519 if err == nil { 520 pathValue, err := jmespath.Search("botLocaleStatus", output) 521 if err != nil { 522 return false, fmt.Errorf("error evaluating waiter state: %w", err) 523 } 524 525 expectedValue := "Built" 526 value, ok := pathValue.(types.BotLocaleStatus) 527 if !ok { 528 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 529 } 530 531 if string(value) == expectedValue { 532 return false, nil 533 } 534 } 535 536 if err == nil { 537 pathValue, err := jmespath.Search("botLocaleStatus", output) 538 if err != nil { 539 return false, fmt.Errorf("error evaluating waiter state: %w", err) 540 } 541 542 expectedValue := "ReadyExpressTesting" 543 value, ok := pathValue.(types.BotLocaleStatus) 544 if !ok { 545 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 546 } 547 548 if string(value) == expectedValue { 549 return false, nil 550 } 551 } 552 553 if err == nil { 554 pathValue, err := jmespath.Search("botLocaleStatus", output) 555 if err != nil { 556 return false, fmt.Errorf("error evaluating waiter state: %w", err) 557 } 558 559 expectedValue := "NotBuilt" 560 value, ok := pathValue.(types.BotLocaleStatus) 561 if !ok { 562 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 563 } 564 565 if string(value) == expectedValue { 566 return false, nil 567 } 568 } 569 570 if err == nil { 571 pathValue, err := jmespath.Search("botLocaleStatus", output) 572 if err != nil { 573 return false, fmt.Errorf("error evaluating waiter state: %w", err) 574 } 575 576 expectedValue := "Deleting" 577 value, ok := pathValue.(types.BotLocaleStatus) 578 if !ok { 579 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 580 } 581 582 if string(value) == expectedValue { 583 return false, fmt.Errorf("waiter state transitioned to Failure") 584 } 585 } 586 587 if err == nil { 588 pathValue, err := jmespath.Search("botLocaleStatus", output) 589 if err != nil { 590 return false, fmt.Errorf("error evaluating waiter state: %w", err) 591 } 592 593 expectedValue := "Failed" 594 value, ok := pathValue.(types.BotLocaleStatus) 595 if !ok { 596 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 597 } 598 599 if string(value) == expectedValue { 600 return false, fmt.Errorf("waiter state transitioned to Failure") 601 } 602 } 603 604 return true, nil 605} 606 607// BotLocaleExpressTestingAvailableWaiterOptions are waiter options for 608// BotLocaleExpressTestingAvailableWaiter 609type BotLocaleExpressTestingAvailableWaiterOptions struct { 610 611 // Set of options to modify how an operation is invoked. These apply to all 612 // operations invoked for this client. Use functional options on operation call to 613 // modify this list for per operation behavior. 614 APIOptions []func(*middleware.Stack) error 615 616 // MinDelay is the minimum amount of time to delay between retries. If unset, 617 // BotLocaleExpressTestingAvailableWaiter will use default minimum delay of 10 618 // seconds. Note that MinDelay must resolve to a value lesser than or equal to the 619 // MaxDelay. 620 MinDelay time.Duration 621 622 // MaxDelay is the maximum amount of time to delay between retries. If unset or set 623 // to zero, BotLocaleExpressTestingAvailableWaiter will use default max delay of 624 // 120 seconds. Note that MaxDelay must resolve to value greater than or equal to 625 // the MinDelay. 626 MaxDelay time.Duration 627 628 // LogWaitAttempts is used to enable logging for waiter retry attempts 629 LogWaitAttempts bool 630 631 // Retryable is function that can be used to override the service defined 632 // waiter-behavior based on operation output, or returned error. This function is 633 // used by the waiter to decide if a state is retryable or a terminal state. By 634 // default service-modeled logic will populate this option. This option can thus be 635 // used to define a custom waiter state with fall-back to service-modeled waiter 636 // state mutators.The function returns an error in case of a failure state. In case 637 // of retry state, this function returns a bool value of true and nil error, while 638 // in case of success it returns a bool value of false and nil error. 639 Retryable func(context.Context, *DescribeBotLocaleInput, *DescribeBotLocaleOutput, error) (bool, error) 640} 641 642// BotLocaleExpressTestingAvailableWaiter defines the waiters for 643// BotLocaleExpressTestingAvailable 644type BotLocaleExpressTestingAvailableWaiter struct { 645 client DescribeBotLocaleAPIClient 646 647 options BotLocaleExpressTestingAvailableWaiterOptions 648} 649 650// NewBotLocaleExpressTestingAvailableWaiter constructs a 651// BotLocaleExpressTestingAvailableWaiter. 652func NewBotLocaleExpressTestingAvailableWaiter(client DescribeBotLocaleAPIClient, optFns ...func(*BotLocaleExpressTestingAvailableWaiterOptions)) *BotLocaleExpressTestingAvailableWaiter { 653 options := BotLocaleExpressTestingAvailableWaiterOptions{} 654 options.MinDelay = 10 * time.Second 655 options.MaxDelay = 120 * time.Second 656 options.Retryable = botLocaleExpressTestingAvailableStateRetryable 657 658 for _, fn := range optFns { 659 fn(&options) 660 } 661 return &BotLocaleExpressTestingAvailableWaiter{ 662 client: client, 663 options: options, 664 } 665} 666 667// Wait calls the waiter function for BotLocaleExpressTestingAvailable waiter. The 668// maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is 669// required and must be greater than zero. 670func (w *BotLocaleExpressTestingAvailableWaiter) Wait(ctx context.Context, params *DescribeBotLocaleInput, maxWaitDur time.Duration, optFns ...func(*BotLocaleExpressTestingAvailableWaiterOptions)) error { 671 if maxWaitDur <= 0 { 672 return fmt.Errorf("maximum wait time for waiter must be greater than zero") 673 } 674 675 options := w.options 676 for _, fn := range optFns { 677 fn(&options) 678 } 679 680 if options.MaxDelay <= 0 { 681 options.MaxDelay = 120 * time.Second 682 } 683 684 if options.MinDelay > options.MaxDelay { 685 return fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) 686 } 687 688 ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) 689 defer cancelFn() 690 691 logger := smithywaiter.Logger{} 692 remainingTime := maxWaitDur 693 694 var attempt int64 695 for { 696 697 attempt++ 698 apiOptions := options.APIOptions 699 start := time.Now() 700 701 if options.LogWaitAttempts { 702 logger.Attempt = attempt 703 apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) 704 apiOptions = append(apiOptions, logger.AddLogger) 705 } 706 707 out, err := w.client.DescribeBotLocale(ctx, params, func(o *Options) { 708 o.APIOptions = append(o.APIOptions, apiOptions...) 709 }) 710 711 retryable, err := options.Retryable(ctx, params, out, err) 712 if err != nil { 713 return err 714 } 715 if !retryable { 716 return nil 717 } 718 719 remainingTime -= time.Since(start) 720 if remainingTime < options.MinDelay || remainingTime <= 0 { 721 break 722 } 723 724 // compute exponential backoff between waiter retries 725 delay, err := smithywaiter.ComputeDelay( 726 attempt, options.MinDelay, options.MaxDelay, remainingTime, 727 ) 728 if err != nil { 729 return fmt.Errorf("error computing waiter delay, %w", err) 730 } 731 732 remainingTime -= delay 733 // sleep for the delay amount before invoking a request 734 if err := smithytime.SleepWithContext(ctx, delay); err != nil { 735 return fmt.Errorf("request cancelled while waiting, %w", err) 736 } 737 } 738 return fmt.Errorf("exceeded max wait time for BotLocaleExpressTestingAvailable waiter") 739} 740 741func botLocaleExpressTestingAvailableStateRetryable(ctx context.Context, input *DescribeBotLocaleInput, output *DescribeBotLocaleOutput, err error) (bool, error) { 742 743 if err == nil { 744 pathValue, err := jmespath.Search("botLocaleStatus", output) 745 if err != nil { 746 return false, fmt.Errorf("error evaluating waiter state: %w", err) 747 } 748 749 expectedValue := "Built" 750 value, ok := pathValue.(types.BotLocaleStatus) 751 if !ok { 752 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 753 } 754 755 if string(value) == expectedValue { 756 return false, nil 757 } 758 } 759 760 if err == nil { 761 pathValue, err := jmespath.Search("botLocaleStatus", output) 762 if err != nil { 763 return false, fmt.Errorf("error evaluating waiter state: %w", err) 764 } 765 766 expectedValue := "ReadyExpressTesting" 767 value, ok := pathValue.(types.BotLocaleStatus) 768 if !ok { 769 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 770 } 771 772 if string(value) == expectedValue { 773 return false, nil 774 } 775 } 776 777 if err == nil { 778 pathValue, err := jmespath.Search("botLocaleStatus", output) 779 if err != nil { 780 return false, fmt.Errorf("error evaluating waiter state: %w", err) 781 } 782 783 expectedValue := "Deleting" 784 value, ok := pathValue.(types.BotLocaleStatus) 785 if !ok { 786 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 787 } 788 789 if string(value) == expectedValue { 790 return false, fmt.Errorf("waiter state transitioned to Failure") 791 } 792 } 793 794 if err == nil { 795 pathValue, err := jmespath.Search("botLocaleStatus", output) 796 if err != nil { 797 return false, fmt.Errorf("error evaluating waiter state: %w", err) 798 } 799 800 expectedValue := "Failed" 801 value, ok := pathValue.(types.BotLocaleStatus) 802 if !ok { 803 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 804 } 805 806 if string(value) == expectedValue { 807 return false, fmt.Errorf("waiter state transitioned to Failure") 808 } 809 } 810 811 if err == nil { 812 pathValue, err := jmespath.Search("botLocaleStatus", output) 813 if err != nil { 814 return false, fmt.Errorf("error evaluating waiter state: %w", err) 815 } 816 817 expectedValue := "NotBuilt" 818 value, ok := pathValue.(types.BotLocaleStatus) 819 if !ok { 820 return false, fmt.Errorf("waiter comparator expected types.BotLocaleStatus value, got %T", pathValue) 821 } 822 823 if string(value) == expectedValue { 824 return false, fmt.Errorf("waiter state transitioned to Failure") 825 } 826 } 827 828 return true, nil 829} 830 831func newServiceMetadataMiddleware_opDescribeBotLocale(region string) *awsmiddleware.RegisterServiceMetadata { 832 return &awsmiddleware.RegisterServiceMetadata{ 833 Region: region, 834 ServiceID: ServiceID, 835 SigningName: "lex", 836 OperationName: "DescribeBotLocale", 837 } 838} 839