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
                }
            });
        }
Beispiel #2
0
        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
                }
            });
        }
Beispiel #3
0
        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";
        }
Beispiel #4
0
        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
                }
            });
        }