コード例 #1
0
        private async Task OnMessageReceived(Message message, CancellationToken cancelToken)
        {
            logger.LogInformation($"Processing message [{message.MessageId}]...");

            if (cancelToken.IsCancellationRequested)
            {
                logger.LogWarning($"Cancellation requested. Abandoning message [{message.MessageId}]...");

                await subscriptionClient.AbandonAsync(message.SystemProperties.LockToken);
            }
            else
            {
                try
                {
                    var messageJson      = Encoding.UTF8.GetString(message.Body);
                    var executionRequest = JsonConvert.DeserializeObject <ExecutionRequest>(messageJson);

                    logger.LogInformation($"Processing execution request [{executionRequest.ExecutionId}]...");

                    await requestRouter.RouteRequestAsync(executionRequest, cancelToken);

                    logger.LogInformation($"Execution request [{executionRequest.ExecutionId}] successfully processed.");

                    await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
                }
                catch (Exception ex)
                {
                    logger.LogError($"An error occurred while processing message [{message.MessageId}]: [{ex.Message}]. " +
                                    $"Abandoning message [{message.MessageId}]...");

                    await subscriptionClient.AbandonAsync(message.SystemProperties.LockToken);
                }
            }
        }
コード例 #2
0
        private async Task <Core.Models.Execution> ExecuteAsync(IExecutionRequestContext erContext)
        {
            // Dispatch the execution request to the execution pipeline...
            // For more information on the execution pipeline, see /doc/architecture/execution-pipeline.md.

            var execRequest = ToExecutionRequestAsync(erContext);
            var execContext = await execRequestRouter.RouteRequestAsync(execRequest, CancellationToken.None);

            // The result of all this processing is an execution context (/src/draco/core/Core.Models/ExecutionContext.cs).
            // An execution context contains all the information that the execution request does + an execution status update that includes
            // status, description, percentage complete, validation errors, etc. This execution context is then applied to the core execution model.

            erContext.Execution = ApplyExecutionContext(execContext, erContext.Execution);

            // Save the updated execution...

            await UpdateExecutionAsync(erContext.Execution);

            return(erContext.Execution);
        }
コード例 #3
0
        public async Task <IActionResult> ExecuteAsync([FromBody] ExecutionRequestApiModel execRequestApiModel)
        {
            // Validate the provided execution request...

            var errors = execRequestApiModel.ValidateApiModel().ToList();

            // If the request is invalid, respond with [400 Bad Request] + detailed error description...

            if (errors.Any())
            {
                return(BadRequest($"[{errors.Count}] errors occurred while attempting to process your request: {string.Join(' ', errors)}"));
            }

            // Convert the execution request API model to a core model and hand it off to the execution pipeline.
            // For more information on the execution pipeline, see /doc/architecture/execution-pipeline.md.

            var execRequest = execRequestApiModel.ToCoreModel();
            var execContext = await execRequestRouter.RouteRequestAsync(execRequest, CancellationToken.None);

            // At this point, even if the execution itself failed, we did our job.
            // Respond with [200 OK] + an execution update...

            return(Ok(execContext.ToApiModel()));
        }