public async Task <GetActionResponse> GetAction(GetActionRequest request)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            try {
                var getActionTask = _lambdaClient.InvokeAsync(new InvokeRequest {
                    Payload = JsonSerializer.Serialize(new BotRequest {
                        Command = BotCommand.GetAction,
                        Session = request.Session,
                        Bot     = request.Bot
                    }),
                    FunctionName   = _lambdaArn,
                    InvocationType = InvocationType.RequestResponse
                });

                // check if lambda responds within time limit
                if (await Task.WhenAny(getActionTask, Task.Delay(_requestTimeout)) != getActionTask)
                {
                    _logger?.LogInfo($"Bot {_botId} GetAction timed out after {stopwatch.Elapsed.TotalSeconds:N2}s");
                    return(null);
                }
                var response = Encoding.UTF8.GetString(getActionTask.Result.Payload.ToArray());
                var result   = JsonSerializer.Deserialize <BotResponse>(response);
                _logger?.LogInfo($"Bot {_botId} GetAction responded in {stopwatch.Elapsed.TotalSeconds:N2}s:\n{response}");
                return(result.BotAction);
            } catch (Exception e) {
                _logger?.LogErrorAsInfo(e, $"Bot {_botId} GetAction failed (arn: {_lambdaArn})");
                return(null);
            }
        }
示例#2
0
        internal virtual GetActionResponse GetAction(GetActionRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetActionRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetActionResponseUnmarshaller.Instance;

            return(Invoke <GetActionResponse>(request, options));
        }
示例#3
0
        /// <summary>
        /// Gets information about the specified FIS action.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetAction service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the GetAction service method, as returned by FIS.</returns>
        /// <exception cref="Amazon.FIS.Model.ResourceNotFoundException">
        /// The specified resource cannot be found.
        /// </exception>
        /// <exception cref="Amazon.FIS.Model.ValidationException">
        /// The specified input is not valid, or fails to satisfy the constraints for the request.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/fis-2020-12-01/GetAction">REST API Reference for GetAction Operation</seealso>
        public virtual Task <GetActionResponse> GetActionAsync(GetActionRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetActionRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetActionResponseUnmarshaller.Instance;

            return(InvokeAsync <GetActionResponse>(request, options, cancellationToken));
        }
示例#4
0
        public async Task <IActionResult> PostActionAsync([FromBody] GetActionRequest request)
        {
            var response = await _mediator.Send(request);

            return(Ok(response));
        }