예제 #1
0
        internal virtual SendTaskSuccessResponse SendTaskSuccess(SendTaskSuccessRequest request)
        {
            var marshaller   = new SendTaskSuccessRequestMarshaller();
            var unmarshaller = SendTaskSuccessResponseUnmarshaller.Instance;

            return(Invoke <SendTaskSuccessRequest, SendTaskSuccessResponse>(request, marshaller, unmarshaller));
        }
예제 #2
0
        private async Task SendSuccessAsync()
        {
            AmazonStepFunctionsClient client         = new AmazonStepFunctionsClient();
            SendTaskSuccessRequest    successRequest = new SendTaskSuccessRequest();

            successRequest.TaskToken = taskToken;
            Dictionary <String, String> result = new Dictionary <String, String>
            {
                { "Result", "Success" },
                { "Message", "Completed" }
            };

            string requestOutput = JsonConvert.SerializeObject(result, Formatting.Indented);

            successRequest.Output = requestOutput;
            try
            {
                await client.SendTaskSuccessAsync(successRequest);
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR : SendSuccessAsync : " + error.Message);
                Console.WriteLine("ERROR : SendSuccessAsync : " + error.StackTrace);
            }
            await Task.CompletedTask;
        }
예제 #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendTaskSuccess operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SendTaskSuccess operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/states-2016-11-23/SendTaskSuccess">REST API Reference for SendTaskSuccess Operation</seealso>
        public virtual Task <SendTaskSuccessResponse> SendTaskSuccessAsync(SendTaskSuccessRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new SendTaskSuccessRequestMarshaller();
            var unmarshaller = SendTaskSuccessResponseUnmarshaller.Instance;

            return(InvokeAsync <SendTaskSuccessRequest, SendTaskSuccessResponse>(request, marshaller,
                                                                                 unmarshaller, cancellationToken));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the SendTaskSuccess operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SendTaskSuccess operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/states-2016-11-23/SendTaskSuccess">REST API Reference for SendTaskSuccess Operation</seealso>
        public virtual Task <SendTaskSuccessResponse> SendTaskSuccessAsync(SendTaskSuccessRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = SendTaskSuccessRequestMarshaller.Instance;
            options.ResponseUnmarshaller = SendTaskSuccessResponseUnmarshaller.Instance;

            return(InvokeAsync <SendTaskSuccessResponse>(request, options, cancellationToken));
        }
        internal virtual SendTaskSuccessResponse SendTaskSuccess(SendTaskSuccessRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = SendTaskSuccessRequestMarshaller.Instance;
            options.ResponseUnmarshaller = SendTaskSuccessResponseUnmarshaller.Instance;

            return(Invoke <SendTaskSuccessResponse>(request, options));
        }
 private static async Task CompleteWaitForResponseAsync(string taskToken, State state)
 {
     using (var client = StepFunctionClientFactory.GetClient())
     {
         var req = new SendTaskSuccessRequest
         {
             TaskToken = taskToken,
             Output    = JsonConvert.SerializeObject(state)
         };
         await client.SendTaskSuccessAsync(req).ConfigureAwait(false);
     }
 }
예제 #7
0
        public async Task <Response> Handle(SQSEvent sqsEvent, CancellationToken cancellationToken = default)
        {
            var request        = requestFactory.CreateFromSqsEvent(sqsEvent);
            var bucket         = config.StateStore;
            var getObjResponse = await s3GetObjectFacade.TryGetObject <StateInfo>(bucket, $"{request.Pipeline}/state.json");

            var stateInfo = getObjResponse ?? new StateInfo
            {
                LastCommitTimestamp = DateTime.MinValue
            };

            var superseded      = request.CommitTimestamp < stateInfo.LastCommitTimestamp;
            var sendTaskRequest = new SendTaskSuccessRequest
            {
                TaskToken = request.Token,
                Output    = Serialize(new
                {
                    Superseded = superseded
                })
            };

            var sendTaskResponse = await stepFunctionsClient.SendTaskSuccessAsync(sendTaskRequest, cancellationToken);

            logger.LogInformation($"Got send task response: {Serialize(sendTaskResponse)}");

            if (!superseded)
            {
                var putObjectRequest = new PutObjectRequest
                {
                    BucketName  = bucket,
                    Key         = $"{request.Pipeline}/state.json",
                    ContentBody = Serialize(new StateInfo
                    {
                        LastCommitTimestamp = request.CommitTimestamp
                    })
                };

                var putObjectResponse = await s3Client.PutObjectAsync(putObjectRequest, cancellationToken);

                logger.LogInformation($"Got put object response: {Serialize(putObjectResponse)}");
            }

            return(new Response
            {
                Success = true
            });
        }
예제 #8
0
        private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context)
        {
            context.Logger.LogLine($"Processed message {message.Body}");
            var messageBody = JsonSerializer.Deserialize <TaskMessage>(message.Body);

            context.Logger.LogLine("");
            var stepFunctionsClient = GetStepFunctionsClient();

            var req = new SendTaskSuccessRequest
            {
                Output    = "\"Callback task completed successfully(updated again!).\"",
                TaskToken = messageBody.TaskToken
            };
            await stepFunctionsClient.SendTaskSuccessAsync(req);

            await Task.CompletedTask;
        }
예제 #9
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="request">Instance of APIGatewayProxyRequest</param>
        /// <param name="context">AWS Lambda Context</param>
        /// <returns>Instance of APIGatewayProxyResponse</returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var body = JsonConvert.DeserializeObject <Dictionary <string, string> >(request?.Body);

            var isIncidentId = Guid.TryParse(body["IncidentId"], out var incidentId);
            var isExamId     = Guid.TryParse(body["ExamId"], out var examId);
            var isScore      = Int32.TryParse(body["Score"], out var score);
            var token        = body["TaskToken"];

            if (!isIncidentId || !isExamId | !isScore | !(token.Length >= 1 & token.Length <= 1024))
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json" }
                    }
                });
            }

            Console.WriteLine($"IncidentId: {incidentId}");
            Console.WriteLine($"ExamId: {examId}");
            Console.WriteLine($"Score: {score}");
            Console.WriteLine($"Token: {token}");

            var incident = _incidentRepository.GetIncidentById(incidentId);
            var exam     = incident.Exams.Find(e => e.ExamId == examId);

            exam.Score = score;

            _incidentRepository.SaveIncident(incident);

            Console.WriteLine(JsonConvert.SerializeObject(incident));

            var sendTaskSuccessRequest = new SendTaskSuccessRequest
            {
                TaskToken = token,
                Output    = JsonConvert.SerializeObject(incident)
            };

            try
            {
                _amazonStepFunctionsClient.SendTaskSuccessAsync(sendTaskSuccessRequest).Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Headers = new Dictionary <string, string> {
                    { "Content-Type", "application/json" },
                    { "Access-Control-Allow-Origin", "*" },
                    { "Access-Control-Allow-Headers", "Content-Type" },
                    { "Access-Control-Allow-Methods", "OPTIONS,POST" }
                }
            });
        }