private void PublishExceptionAsync(ProcessingCommand processingCommand, IPublishableException exception, int retryTimes)
 {
     _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("PublishExceptionAsync",
                                                           () => _exceptionPublisher.PublishAsync(exception),
                                                           currentRetryTimes => PublishExceptionAsync(processingCommand, exception, currentRetryTimes),
                                                           result =>
     {
         NotifyCommandExecuted(processingCommand, CommandStatus.Failed, exception.GetType().Name, (exception as Exception).Message);
     },
                                                           () =>
     {
         var serializableInfo = new Dictionary <string, string>();
         exception.SerializeTo(serializableInfo);
         var exceptionInfo = string.Join(",", serializableInfo.Select(x => string.Format("{0}:{1}", x.Key, x.Value)));
         return(string.Format("[commandId:{0}, exceptionInfo:{1}]", processingCommand.Message.Id, exceptionInfo));
     },
                                                           () => NotifyCommandExecuted(processingCommand, CommandStatus.Failed, null, "Publish exception async failed."),
                                                           retryTimes);
 }
 private void PublishExceptionAsync(ProcessingCommand processingCommand, IPublishableException exception, int retryTimes)
 {
     _ioHelper.TryAsyncActionRecursively("PublishExceptionAsync",
                                         () => _exceptionPublisher.PublishAsync(exception),
                                         currentRetryTimes => PublishExceptionAsync(processingCommand, exception, currentRetryTimes),
                                         result =>
     {
         CompleteCommand(processingCommand, CommandStatus.Failed, exception.GetType().Name, (exception as Exception).Message);
     },
                                         () =>
     {
         var serializableInfo = new Dictionary <string, string>();
         exception.SerializeTo(serializableInfo);
         var exceptionInfo = string.Join(",", serializableInfo.Select(x => string.Format("{0}:{1}", x.Key, x.Value)));
         return(string.Format("[commandId:{0}, exceptionInfo:{1}]", processingCommand.Message.Id, exceptionInfo));
     },
                                         errorMessage =>
     {
         _logger.Fatal(string.Format("Publish event has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage));
     },
                                         retryTimes, true);
 }
Beispiel #3
0
        private Task PublishExceptionAsync(ProcessingCommand processingCommand, IPublishableException exception, int retryTimes, TaskCompletionSource <bool> taskSource)
        {
            exception.MergeItems(processingCommand.Message.Items);

            _ioHelper.TryAsyncActionRecursively("PublishExceptionAsync",
                                                () => _exceptionPublisher.PublishAsync(exception),
                                                currentRetryTimes => PublishExceptionAsync(processingCommand, exception, currentRetryTimes, taskSource),
                                                async result =>
            {
                await CompleteCommand(processingCommand, CommandStatus.Failed, exception.GetType().Name, (exception as Exception).Message);
                taskSource.SetResult(true);
            },
                                                () =>
            {
                var serializableInfo = new Dictionary <string, string>();
                exception.SerializeTo(serializableInfo);
                var exceptionInfo = string.Join(",", serializableInfo.Select(x => string.Format("{0}:{1}", x.Key, x.Value)));
                return(string.Format("[commandId:{0}, exceptionInfo:{1}]", processingCommand.Message.Id, exceptionInfo));
            },
                                                null,
                                                retryTimes, true);

            return(taskSource.Task);
        }