Пример #1
0
        private void CreateExecutionError(Task <ConsumerResult> requestForwarderResult, Guid executionId, DateTime startDate, DateTime endDate, TimeSpan duration)
        {
            var executionInfo  = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Error, executionId);
            var executionEntry = new ExecutionHistory(_resourceId, "", executionInfo, _userName);

            executionEntry.Exception = requestForwarderResult.Exception;
            executionEntry.AuditType = "Error";
            _logger.ExecutionFailed(executionEntry);
        }
Пример #2
0
        public Task <ConsumerResult> Consume(byte[] body)
        {
            var    executionId = Guid.NewGuid();
            string strBody     = System.Text.Encoding.UTF8.GetString(body);

            _logger.StartExecution($"processing body {strBody}");
            var startDate = DateTime.UtcNow;

            var task = _consumer.Consume(body);

            task.ContinueWith((requestForwarderResult) =>
            {
                var endDate  = DateTime.UtcNow;
                var duration = endDate - startDate;

                _logger.Warn($"failure processing body {strBody}");
                var executionInfo        = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Error, executionId);
                var executionEntry       = new ExecutionHistory(_resourceId, "", executionInfo, _userName);
                executionEntry.Exception = requestForwarderResult.Exception;

                _logger.ExecutionFailed(executionEntry);
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.ContinueWith((requestForwarderResult) =>
            {
                var endDate  = DateTime.UtcNow;
                var duration = endDate - startDate;

                if (requestForwarderResult.Result == ConsumerResult.Success)
                {
                    _logger.Info($"success processing body{strBody}");
                    var executionInfo  = new ExecutionInfo(startDate, duration, endDate, Warewolf.Triggers.QueueRunStatus.Success, executionId);
                    var executionEntry = new ExecutionHistory(_resourceId, "", executionInfo, _userName);

                    _logger.ExecutionSucceeded(executionEntry);
                }
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            if (task.IsFaulted)
            {
                return(Task.Run(() => ConsumerResult.Failed));
            }
            else
            {
                return(Task.Run(() => ConsumerResult.Success));
            }
        }