Beispiel #1
0
        private static async Task ProcessNotificationAsync(McmaApiRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(ProcessNotificationAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var notification = request.JsonBody.ToMcmaObject <Notification>();

            if (notification == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing notification in request body";
                return;
            }

            if (notification.Content == null)
            {
                response.StatusCode    = (int)HttpStatusCode.BadRequest;
                response.StatusMessage = "Missing notification content";
                return;
            }

            var job = notification.Content.ToMcmaObject <Job>();

            var taskToken = request.QueryStringParameters["taskToken"];

            var stepFunctionClient = new AmazonStepFunctionsClient();

            switch (job.Status)
            {
            case "COMPLETED":
                Logger.Debug($"Sending task success for task token {taskToken}");
                await stepFunctionClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                {
                    TaskToken = taskToken,
                    Output    = $"\"{notification.Source}\""
                });

                break;

            case "FAILED":
                Logger.Debug($"Sending task failure for task token {taskToken}");
                var error = job.Type + " failed execution";
                var cause = job.Type + " with id '" + job.Id + "' failed execution with statusMessage '" + job.StatusMessage + "'";

                await stepFunctionClient.SendTaskFailureAsync(new SendTaskFailureRequest
                {
                    TaskToken = taskToken,
                    Error     = error,
                    Cause     = cause
                });

                break;
            }
        }
        private static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext)
        {
            Logger.Debug(nameof(ProcessNotificationAsync));
            Logger.Debug(requestContext.Request.ToMcmaJson().ToString());

            if (requestContext.IsBadRequestDueToMissingBody(out Notification notification))
            {
                return;
            }

            if (notification.Content == null)
            {
                requestContext.Response.StatusCode    = (int)HttpStatusCode.BadRequest;
                requestContext.Response.StatusMessage = "Missing notification content";
                return;
            }

            var job = notification.Content.ToMcmaObject <Job>();

            var taskToken = requestContext.Request.QueryStringParameters["taskToken"];

            if (job.Status == JobStatus.Completed)
            {
                using (var stepFunctionClient = new AmazonStepFunctionsClient())
                    await stepFunctionClient.SendTaskSuccessAsync(new SendTaskSuccessRequest
                    {
                        TaskToken = taskToken,
                        Output    = $"\"{notification.Source}\""
                    });
            }
            else if (job.Status == JobStatus.Failed)
            {
                using (var stepFunctionClient = new AmazonStepFunctionsClient())
                    await stepFunctionClient.SendTaskFailureAsync(new SendTaskFailureRequest
                    {
                        TaskToken = taskToken,
                        Error     = job.Type + " failed execution",
                        Cause     = job.Type + " with id '" + job.Id + "' failed execution with statusMessage '" + job.StatusMessage + "'"
                    });
            }
            else
            {
                Logger.Debug($"Ignoring notification for updated status of '{job.Status}'");
            }
        }
Beispiel #3
0
        private async Task SendFailureAsync(String failureCause, String failureError)
        {
            AmazonStepFunctionsClient client         = new AmazonStepFunctionsClient();
            SendTaskFailureRequest    failureRequest = new SendTaskFailureRequest();

            failureRequest.Cause     = failureCause;
            failureRequest.Error     = failureError;
            failureRequest.TaskToken = taskToken;

            try
            {
                await client.SendTaskFailureAsync(failureRequest);
            }
            catch (Exception error)
            {
                Console.WriteLine("ERROR : SendFailureAsync : " + error.Message);
                Console.WriteLine("ERROR : SendFailureAsync : " + error.StackTrace);
            }
            await Task.CompletedTask;
        }