public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext) { var table = new DynamoDbTable <JobAssignment>(requestContext.TableName()); var jobAssignment = await table.GetAsync(requestContext.PublicUrl() + "/job-assignments/" + requestContext.Request.PathVariables["id"]); if (!requestContext.ResourceIfFound(jobAssignment, false) || requestContext.IsBadRequestDueToMissingBody(out Notification notification)) { return; } await WorkerInvoker.RunAsync( requestContext.WorkerFunctionName(), new { operationName = "ProcessNotification", contextVariables = requestContext.GetAllContextVariables(), input = new { jobAssignmentId = jobAssignment.Id, notification = notification } }); }
public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext) { var request = requestContext.Request; var response = requestContext.Response; var table = new DynamoDbTable <JobProcess>(requestContext.TableName()); var jobProcess = await table.GetAsync(requestContext.PublicUrl() + "/job-processes/" + request.PathVariables["id"]); if (!requestContext.ResourceIfFound(jobProcess, false) || requestContext.IsBadRequestDueToMissingBody <Notification>(out var notification)) { return; } if (jobProcess.JobAssignment != notification.Source) { response.StatusCode = (int)HttpStatusCode.BadRequest; response.StatusMessage = "Unexpected notification from '" + notification.Source + "'."; return; } await WorkerInvoker.RunAsync( requestContext.WorkerFunctionName(), new { operationName = "processNotification", contextVariables = requestContext.GetAllContextVariables(), input = new { jobProcessId = jobProcess.Id, notification = notification } }); }
public static async Task CancelJobAsync(McmaApiRequestContext requestContext) { var table = new DynamoDbTable <Job>(requestContext.TableName()); var jobId = requestContext.PublicUrl() + "/jobs/" + requestContext.Request.PathVariables["id"]; if (!requestContext.ResourceIfFound(await table.GetAsync(jobId), false)) { return; } requestContext.Response.StatusCode = (int)HttpStatusCode.NotImplemented; requestContext.Response.StatusMessage = "Stopping job is not implemented"; }
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}'"); } }
public static async Task ProcessNotificationAsync(McmaApiRequestContext requestContext) { Logger.Debug(nameof(ProcessNotificationAsync)); Logger.Debug(requestContext.Request.ToMcmaJson().ToString()); var table = new DynamoDbTable <JobAssignment>(requestContext.TableName()); var jobAssignmentId = requestContext.PublicUrl() + "/job-assignments/" + requestContext.Request.PathVariables["id"]; var jobAssignment = await table.GetAsync(jobAssignmentId); Logger.Debug("jobAssignment = {0}", jobAssignment); if (!requestContext.ResourceIfFound(jobAssignment, false)) { return; } var notification = requestContext.Request.QueryStringParameters; Logger.Debug("notification = {0}", notification); if (notification == null || !notification.Any()) { requestContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; requestContext.Response.StatusMessage = "Missing notification in request Query String"; return; } var lambdaWorkerInvoker = new LambdaWorkerInvoker(); await lambdaWorkerInvoker.RunAsync( requestContext.WorkerFunctionName(), new { operationName = "ProcessNotification", contextVariables = requestContext.GetAllContextVariables(), input = new { jobAssignmentId, notification } }); }