Exemple #1
0
        private async Task BuildBotAsync(CancellationToken cancellationToken)
        {
            // Get the latest bot configuration
            var getBotRequest = new GetBotRequest
            {
                Name           = this.LexBotName,
                VersionOrAlias = "$LATEST",
            };

            var getBotResponse = await this.LexClient.GetBotAsync(getBotRequest, cancellationToken).ConfigureAwait(false);

            // Call PutBot with the latest GetBot response
            var putBotBuildRequest = JObject.FromObject(getBotResponse).ToObject <PutBotRequest>();

            putBotBuildRequest.CreateVersion   = true;
            putBotBuildRequest.ProcessBehavior = ProcessBehavior.BUILD;

            // Workaround for error received from Lex client
            putBotBuildRequest.AbortStatement.Messages.First().GroupNumber      = 1;
            putBotBuildRequest.ClarificationPrompt.Messages.First().GroupNumber = 1;

            Logger.LogTrace($"Building bot '{this.LexBotName}'.");

            await this.LexClient.PutBotAsync(putBotBuildRequest, cancellationToken).ConfigureAwait(false);

            // Poll for until bot is ready
            await this.PollBotReadyStatusAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #2
0
        private async Task PollBotReadyStatusAsync(CancellationToken cancellationToken)
        {
            var getBotRequest = new GetBotRequest
            {
                Name           = this.LexBotName,
                VersionOrAlias = "$LATEST",
            };

            // Wait for Ready status
            var count = 0;

            while (true)
            {
                var getBotResponse = await this.LexClient.GetBotAsync(getBotRequest, cancellationToken).ConfigureAwait(false);

                if (getBotResponse.Status == Status.READY)
                {
                    break;
                }

                // After importing an unchanged bot, a bot status will be "NOT_BUILT"
                if (getBotResponse.Status == Status.NOT_BUILT)
                {
                    break;
                }

                if (getBotResponse.Status == Status.FAILED)
                {
                    var exceptionMessage = string.Join(Environment.NewLine, getBotResponse.FailureReason);
                    throw new InvalidOperationException(exceptionMessage);
                }

                if (getBotResponse.Status != Status.BUILDING)
                {
                    throw new InvalidOperationException(
                              $"Expected bot to have '{Status.BUILDING}', instead found '{getBotResponse.Status}'.");
                }

                // If building, delay with linear backoff
                var delay = TimeSpan.FromSeconds(GetBotDelaySeconds * ++count);
                await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
            }
        }
Exemple #3
0
 public Task <GetBotResponse> GetBotAsync(GetBotRequest request, CancellationToken cancellationToken)
 {
     return(RetryAsync(this.AmazonLexModelClient.GetBotAsync, request, cancellationToken));
 }
Exemple #4
0
 Task <GetBotResponse> ILexBotGeneratorDependencyProvider.GetBotAsync(GetBotRequest request) => _lexBuildingClient.GetBotAsync(request);
Exemple #5
0
            public async Task <GetBotResponse> GetBotAsync(GetBotRequest request, CancellationToken cancellationToken)
            {
                await this.ProcessRequestAsync(request).ConfigureAwait(false);

                return(this.Get <GetBotResponse>());
            }