public async Task Rollback() { try { await contractProvider.Rollback(); Logger.LogInformation($"{baseLogString} Rollback => Rollback on NMS Transaction actor SUCCESSFULLY finished."); } catch (Exception ex) { Logger.LogError($"{baseLogString} Rollback => Exception: {ex.Message}", ex); Logger.LogInformation($"{baseLogString} Rollback => Rollback on NMS Transaction actor UNSUCCESSFULLY finished."); } }
private async Task InvokeRollbackOnActors(string transactionName) { var enumerableActiveTransactions = await ActiveTransactions.GetEnumerableDictionaryAsync(); if (!enumerableActiveTransactions.ContainsKey(transactionName)) { string errorMessage = $"{baseLogString} InvokeRollbackOnActors => transaction '{transactionName}' not found in '{ReliableDictionaryNames.ActiveTransactions}'."; Logger.LogError(errorMessage); throw new Exception(errorMessage); } var result = await TransactionEnlistmentLedger.TryGetValueAsync(transactionName); if (!result.HasValue) { string errorMessage = $"{baseLogString} InvokeRollbackOnActors => Transaction '{transactionName}' not found in '{ReliableDictionaryNames.TransactionEnlistmentLedger}'."; Logger.LogError(errorMessage); throw new Exception(errorMessage); } var transactionLedger = result.Value; List <Task> tasks = new List <Task>(); foreach (var transactionActorName in transactionLedger) { if (enumerableActiveTransactions[transactionName].Contains(transactionActorName)) { var task = Task.Run(async() => { ITransactionActorContract transactionActorClient = TransactionActorClient.CreateClient(transactionActorName); await transactionActorClient.Rollback(); Logger.LogInformation($"{baseLogString} InvokeRollbackOnActors => Rollback invoked on Transaction actor: {transactionActorName}."); }); tasks.Add(task); } } Task.WaitAll(tasks.ToArray()); Logger.LogInformation($"{baseLogString} InvokeRollbackOnActors => Rollback SUCCESSFULLY invoked on all transaction actors."); }