private async Task RootMethodProceed(CompensableMethodContext compensableMethodContext)
        {
            var allDelayCancelExceptionTypes = new HashSet <Type>();

            allDelayCancelExceptionTypes.AddRange(this._delayCancelExceptionTypes);
            allDelayCancelExceptionTypes.AddRange(compensableMethodContext.Compensable.DelayCancelExceptionTypes);


            using (var transaction = _transactionManager.Begin(compensableMethodContext.GetUniqueIdentity()))
            {
                try
                {
                    await compensableMethodContext.MethodInvocation.ProceedAsync();
                }
                catch (Exception ex)
                {
                    if (!_transactionManager.IsDelayCancelException(ex, allDelayCancelExceptionTypes))
                    {
                        _logger.LogError(string.Format("compensable transaction trying failed. transaction content:{0} ", JsonConvert.SerializeObject(transaction)));
                        await _transactionManager.RollbackAsync();
                    }
                    throw ex;
                }

                await _transactionManager.CommitAsync();
            }
        }
Example #2
0
        public async Task CompleteAsync()
        {
            await SaveChangesAsync();

            if (transactionManager.TransactionActive)
            {
                await transactionManager.CommitAsync();
            }

            if (Options.PublishIntegrationEventsOnComplete)
            {
                serviceProvider.GetService <IDistributedEventStore>().PublishEvents();
            }

            Status = UnitOfWorkStatus.Completed;
            OnCompleted();
        }