public static async Task DeleteJobAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteJobAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobId = request.StageVariables["PublicUrl"] + request.Path;

            var job = await table.GetAsync <Job>(jobId);

            if (job == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
                return;
            }

            await table.DeleteAsync <Job>(jobId);

            // invoking worker lambda function that will delete the JobProcess created for this Job
            if (!string.IsNullOrEmpty(job.JobProcess))
            {
                var lambdaClient  = new AmazonLambdaClient();
                var invokeRequest = new InvokeRequest
                {
                    FunctionName   = request.StageVariables["WorkerLambdaFunctionName"],
                    InvocationType = "Event",
                    LogType        = "None",
                    Payload        = new { action = "deleteJobProcess", request = request, jobProcessId = job.JobProcess }.ToMcmaJson().ToString()
                };

                await lambdaClient.InvokeAsync(invokeRequest);
            }
        }
Ejemplo n.º 2
0
        public static async Task DeleteJobAssignmentsAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteJobAssignmentsAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var jobAssignments = await table.GetAllAsync <JobAssignment>();

            foreach (var jobAssignment in jobAssignments)
            {
                await table.DeleteAsync <JobAssignment>(jobAssignment.Id);
            }

            Logger.Debug(response.ToMcmaJson().ToString());
        }
        public static async Task DeleteServiceAsync(ApiGatewayRequest request, McmaApiResponse response)
        {
            Logger.Debug(nameof(DeleteServiceAsync));
            Logger.Debug(request.ToMcmaJson().ToString());

            var table = new DynamoDbTable(request.StageVariables["TableName"]);

            var serviceId = request.StageVariables["PublicUrl"] + request.Path;

            var service = await table.GetAsync <Service>(serviceId);

            if (service == null)
            {
                response.StatusCode    = (int)HttpStatusCode.NotFound;
                response.StatusMessage = "No resource found on path '" + request.Path + "'.";
                return;
            }

            await table.DeleteAsync <Service>(serviceId);
        }