diff --git a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.OrchestrationService/Actors/TestActor.cs b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.OrchestrationService/Actors/TestActor.cs index b84be5d..ec505b3 100644 --- a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.OrchestrationService/Actors/TestActor.cs +++ b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.OrchestrationService/Actors/TestActor.cs @@ -33,10 +33,16 @@ protected override ISaga ReBuildSaga() } var sagaBuilder = Saga.Create(_actorHost.Id.ToString(), this, _logger) - .WithOnSuccessCompletionCallback(OnSuccessCompletionCallbackAsync) - .WithOnRevertedCallback(OnRevertedCallbackAsync) - .WithOnFailedRevertedCallback(OnFailedRevertedCallbackAsync) - .WithOnFailedCallback(OnFailedCallbackAsync); + // Synchronous Callbacks + .WithOnSuccessCompletionCallback(OnSuccessCompletionCallback) + .WithOnRevertedCallback(OnRevertedCallback) + .WithOnFailedRevertedCallback(OnFailedRevertedCallback) + .WithOnFailedCallback(OnFailedCallback) + // Asynchronous Callbacks + .WithOnSuccessCompletionCallbackAsync(OnSuccessCompletionCallbackAsync) + .WithOnRevertedCallbackAsync(OnRevertedCallbackAsync) + .WithOnFailedRevertedCallbackAsync(OnFailedRevertedCallbackAsync) + .WithOnFailedCallbackAsync(OnFailedCallbackAsync); if (_testInfo?.ServiceACall?.InUse ?? false) { @@ -311,58 +317,93 @@ private async Task ValidateRevertCallTestServiceAsync(TestActorOperations #region Saga Completion Methods - private async void OnFailedRevertedCallbackAsync(string sagaLog) + // Synchronous Callback Methods + private void OnSuccessCompletionCallback(string sagaLog) { - _logger.LogError("The Test {TestName} has resulted a failure and left some unused resources. log: {sagaLog}", _testInfo!.TestName, - Environment.NewLine + sagaLog); + _logger.LogError("The Test {TestName} has resulted in success. (Synchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); + var testResult = new TestResult + { + TestInfo = _testInfo, + IsSuccess = true, + SagaLog = sagaLog + }; + Task.Run(() => PublishMessageToSignalRAsync(testResult)); + } + private void OnRevertedCallback(string sagaLog) + { + _logger.LogError("The Test {TestName} has resulted in a failure. All resources are deleted. (Synchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); var testResult = new TestResult { TestInfo = _testInfo, IsSuccess = false, SagaLog = sagaLog }; - - await PublishMessageToSignalRAsync(testResult); + Task.Run(() => PublishMessageToSignalRAsync(testResult)); } - private async void OnRevertedCallbackAsync(string sagaLog) + private void OnFailedRevertedCallback(string sagaLog) { - _logger.LogError("The Test {TestName} has resulted a failure. log: {sagaLog}", _testInfo!.TestName, - Environment.NewLine + sagaLog); - + _logger.LogError("The Test {TestName} has failed and left some unused resources. (Synchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); var testResult = new TestResult { TestInfo = _testInfo, IsSuccess = false, SagaLog = sagaLog }; - - await PublishMessageToSignalRAsync(testResult); + Task.Run(() => PublishMessageToSignalRAsync(testResult)); } - private async void OnFailedCallbackAsync(string sagaLog) + private void OnFailedCallback(string sagaLog) { - _logger.LogError("The Test {TestName} has resulted a failure, starting reverting resources.", _testInfo!.TestName); - - await Task.CompletedTask; + _logger.LogError("The Test {TestName} has failed. Starting to revert resources. (Synchronous Callback)", _testInfo!.TestName); + // Optionally, send a message to the customer } - private async void OnSuccessCompletionCallbackAsync(string sagaLog) + // Asynchronous Callback Methods + private async Task OnSuccessCompletionCallbackAsync(string sagaLog) { - _logger.LogError("The Test {TestName} has resulted a success. log: {sagaLog}", _testInfo!.TestName, - Environment.NewLine + sagaLog); - + _logger.LogError("The Test {TestName} has resulted in success. (Asynchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); var testResult = new TestResult { TestInfo = _testInfo, IsSuccess = true, SagaLog = sagaLog }; + await PublishMessageToSignalRAsync(testResult); + } + private async Task OnRevertedCallbackAsync(string sagaLog) + { + _logger.LogError("The Test {TestName} has resulted in a failure. All resources are deleted. (Asynchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); + var testResult = new TestResult + { + TestInfo = _testInfo, + IsSuccess = false, + SagaLog = sagaLog + }; await PublishMessageToSignalRAsync(testResult); } + private async Task OnFailedRevertedCallbackAsync(string sagaLog) + { + _logger.LogError("The Test {TestName} has failed and left some unused resources. (Asynchronous Callback) log: {sagaLog}", _testInfo!.TestName, sagaLog); + var testResult = new TestResult + { + TestInfo = _testInfo, + IsSuccess = false, + SagaLog = sagaLog + }; + await PublishMessageToSignalRAsync(testResult); + } + + private async Task OnFailedCallbackAsync(string sagaLog) + { + _logger.LogError("The Test {TestName} has failed. Starting to revert resources. (Asynchronous Callback)", _testInfo!.TestName); + // Optionally, send a message to the customer + await Task.CompletedTask; + } + private async Task OnSagaCompletedAsync(object? _, SagaCompletionEventArgs e) { _logger.LogInformation($"Saga {e.SagaId} completed with status {e.Status}"); diff --git a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/MainSagaActor.cs b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/MainSagaActor.cs index 19e65c2..f7dcd1a 100644 --- a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/MainSagaActor.cs +++ b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/MainSagaActor.cs @@ -17,10 +17,17 @@ public MainSagaActor(ActorHost host, ILogger logger, IServiceProv protected override ISaga ReBuildSaga() { var sagaBuilder = Saga.Create(ActorHost.Id.ToString(), this, Logger) - .WithOnSuccessCompletionCallback(OnSuccessCompletionCallbackAsync) - .WithOnRevertedCallback(OnRevertedCallbackAsync) - .WithOnFailedRevertedCallback(OnFailedRevertedCallbackAsync) - .WithOnFailedCallback(OnFailedCallbackAsync) + // Synchronous Callbacks + .WithOnSuccessCompletionCallback(OnSuccessCompletionCallback) + .WithOnRevertedCallback(OnRevertedCallback) + .WithOnFailedRevertedCallback(OnFailedRevertedCallback) + .WithOnFailedCallback(OnFailedCallback) + + // Asynchronous Callbacks + .WithOnSuccessCompletionCallbackAsync(OnSuccessCompletionCallbackAsync) + .WithOnRevertedCallbackAsync(OnRevertedCallbackAsync) + .WithOnFailedRevertedCallbackAsync(OnFailedRevertedCallbackAsync) + .WithOnFailedCallbackAsync(OnFailedCallbackAsync) .WithOperation(MainSagaActorOperations.CallSubSaga) .WithDoOperation(OnCallSubSagaAsync) @@ -67,27 +74,52 @@ public Task GetTestResultAsync() return Task.FromResult(_testResult); } + // Synchronous Callback Methods + private void OnSuccessCompletionCallback(string log) + { + Logger.LogInformation("MainSagaActor completed successfully. (Synchronous Callback)"); + } + + private void OnRevertedCallback(string log) + { + Logger.LogInformation("MainSagaActor reverted successfully. (Synchronous Callback)"); + } + + private void OnFailedRevertedCallback(string log) + { + Logger.LogInformation("MainSagaActor failed to revert. (Synchronous Callback)"); + } + + private void OnFailedCallback(string log) + { + Logger.LogInformation("MainSagaActor failed. (Synchronous Callback)"); + } - private void OnSuccessCompletionCallbackAsync(string obj) + // Asynchronous Callback Methods + private async Task OnSuccessCompletionCallbackAsync(string log) { _testResult = TestResult.Succeeded; - Logger.LogInformation("MainSagaActor completed successfully."); + Logger.LogInformation("MainSagaActor completed successfully. (Asynchronous Callback)"); + await Task.CompletedTask; } - private void OnRevertedCallbackAsync(string obj) + private async Task OnRevertedCallbackAsync(string log) { - Logger.LogInformation("MainSagaActor reverted successfully."); + Logger.LogInformation("MainSagaActor reverted successfully. (Asynchronous Callback)"); + await Task.CompletedTask; } - private void OnFailedRevertedCallbackAsync(string obj) + private async Task OnFailedRevertedCallbackAsync(string log) { - Logger.LogInformation("MainSagaActor failed to revert."); + Logger.LogInformation("MainSagaActor failed to revert. (Asynchronous Callback)"); + await Task.CompletedTask; } - private void OnFailedCallbackAsync(string obj) + private async Task OnFailedCallbackAsync(string log) { _testResult = TestResult.Failed; - Logger.LogInformation("MainSagaActor failed."); + Logger.LogInformation("MainSagaActor failed. (Asynchronous Callback)"); + await Task.CompletedTask; } private async Task OnCallSubSagaAsync() diff --git a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/SubSagaActor.cs b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/SubSagaActor.cs index 7c08ae2..59a2ea8 100644 --- a/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/SubSagaActor.cs +++ b/Sagaway.IntegrationTests/Sagaway.IntegrationTests.TestSubSagaCommunicationService/SubSagaActor.cs @@ -17,10 +17,16 @@ public SubSagaActor(ActorHost host, ILogger logger, IServiceProvid protected override ISaga ReBuildSaga() { var sagaBuilder = Saga.Create(ActorHost.Id.ToString(), this, Logger) - .WithOnSuccessCompletionCallback(OnSuccessCompletionCallbackAsync) - .WithOnRevertedCallback(OnRevertedCallbackAsync) - .WithOnFailedRevertedCallback(OnFailedRevertedCallbackAsync) - .WithOnFailedCallback(OnFailedCallbackAsync) + // Synchronous Callbacks + .WithOnSuccessCompletionCallback(OnSuccessCompletionCallback) + .WithOnRevertedCallback(OnRevertedCallback) + .WithOnFailedRevertedCallback(OnFailedRevertedCallback) + .WithOnFailedCallback(OnFailedCallback) + // Asynchronous Callbacks + .WithOnSuccessCompletionCallbackAsync(OnSuccessCompletionCallbackAsync) + .WithOnRevertedCallbackAsync(OnRevertedCallbackAsync) + .WithOnFailedRevertedCallbackAsync(OnFailedRevertedCallbackAsync) + .WithOnFailedCallbackAsync(OnFailedCallbackAsync) .WithOperation(SubSagaActorOperations.Add) .WithDoOperation(OnAddInSubSagaAsync) @@ -68,7 +74,7 @@ public async Task AddAsync(int a, int b, TimeSpan delay) private async Task OnAddInSubSagaAsync() { //take delay from state store - var delay = StateManager.GetStateAsync("delay").Result; + var delay = await StateManager.GetStateAsync("delay"); Logger.LogInformation("AddInSubSagaAsync called to test the sub-saga with delay {Delay}", delay); await Task.Delay(TimeSpan.FromSeconds(delay)); @@ -93,24 +99,50 @@ public async Task DoneAsync() await CallbackMainSagaAsync(new DoneResult {Result = true}); } - private void OnSuccessCompletionCallbackAsync(string obj) + // Synchronous Callback Methods + private void OnSuccessCompletionCallback(string log) { - Logger.LogInformation("MainSagaActor completed successfully."); + Logger.LogInformation("SubSagaActor completed successfully. (Synchronous Callback)"); } - private void OnRevertedCallbackAsync(string obj) + private void OnRevertedCallback(string log) { - Logger.LogInformation("MainSagaActor reverted successfully."); + Logger.LogInformation("SubSagaActor reverted successfully. (Synchronous Callback)"); } - private void OnFailedRevertedCallbackAsync(string obj) + private void OnFailedRevertedCallback(string log) { - Logger.LogInformation("MainSagaActor failed to revert."); + Logger.LogInformation("SubSagaActor failed to revert. (Synchronous Callback)"); } - private void OnFailedCallbackAsync(string obj) + private void OnFailedCallback(string log) { - Logger.LogInformation("MainSagaActor failed."); + Logger.LogInformation("SubSagaActor failed. (Synchronous Callback)"); + } + + // Asynchronous Callback Methods + private async Task OnSuccessCompletionCallbackAsync(string log) + { + Logger.LogInformation("SubSagaActor completed successfully. (Asynchronous Callback)"); + await Task.CompletedTask; + } + + private async Task OnRevertedCallbackAsync(string log) + { + Logger.LogInformation("SubSagaActor reverted successfully. (Asynchronous Callback)"); + await Task.CompletedTask; + } + + private async Task OnFailedRevertedCallbackAsync(string log) + { + Logger.LogInformation("SubSagaActor failed to revert. (Asynchronous Callback)"); + await Task.CompletedTask; + } + + private async Task OnFailedCallbackAsync(string log) + { + Logger.LogInformation("SubSagaActor failed. (Asynchronous Callback)"); + await Task.CompletedTask; } private Task OnEndSagaAsync() diff --git a/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservation/CarReservationActor.cs b/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservation/CarReservationActor.cs index 8fa8c9c..6e83817 100644 --- a/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservation/CarReservationActor.cs +++ b/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservation/CarReservationActor.cs @@ -26,10 +26,16 @@ public CarReservationActor(ActorHost host, ILogger logger, protected override ISaga ReBuildSaga() { var saga = Saga.Create(_actorHost.Id.ToString(), this, _logger) - .WithOnSuccessCompletionCallback(OnSuccessCompletionCallbackAsync) - .WithOnRevertedCallback(OnRevertedCallbackAsync) - .WithOnFailedRevertedCallback(OnFailedRevertedCallbackAsync) - .WithOnFailedCallback(OnFailedCallbackAsync) + // Synchronous Callbacks + .WithOnSuccessCompletionCallback(OnSuccessCompletionCallback) + .WithOnRevertedCallback(OnRevertedCallback) + .WithOnFailedRevertedCallback(OnFailedRevertedCallback) + .WithOnFailedCallback(OnFailedCallback) + // Asynchronous Callbacks + .WithOnSuccessCompletionCallbackAsync(OnSuccessCompletionCallbackAsync) + .WithOnRevertedCallbackAsync(OnRevertedCallbackAsync) + .WithOnFailedRevertedCallbackAsync(OnFailedRevertedCallbackAsync) + .WithOnFailedCallbackAsync(OnFailedCallbackAsync) .WithOperation(CarReservationActorOperations.CarBooking) .WithDoOperation(BookCarReservationAsync) @@ -336,38 +342,62 @@ private async Task ValidateRevertBillReservationAsync() #region Saga Completion Methods - private async void OnFailedRevertedCallbackAsync(string sagaLog) + // Synchronous Callback Methods + private void OnSuccessCompletionCallback(string sagaLog) { - _logger.LogError("The car reservation has failed and left some unused resources."); + _logger.LogInformation("The car reservation has succeeded. (Synchronous Callback)"); + _logger.LogInformation("The car reservation log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + } + + private void OnRevertedCallback(string sagaLog) + { + _logger.LogError("The car reservation has failed and all resources are deleted. (Synchronous Callback)"); _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); + } - await Task.CompletedTask; + private void OnFailedRevertedCallback(string sagaLog) + { + _logger.LogError("The car reservation has failed and left some unused resources. (Synchronous Callback)"); + _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); } - private async void OnRevertedCallbackAsync(string sagaLog) + private void OnFailedCallback(string sagaLog) { - _logger.LogError("The car reservation has failed and all resources are deleted."); + _logger.LogError("The car reservation has failed starting reverting resources. (Synchronous Callback)"); _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + } + // Asynchronous Callback Methods + private async Task OnSuccessCompletionCallbackAsync(string sagaLog) + { + _logger.LogInformation("The car reservation has succeeded. (Asynchronous Callback)"); + _logger.LogInformation("The car reservation log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer await Task.CompletedTask; } - private async void OnFailedCallbackAsync(string sagaLog) + private async Task OnRevertedCallbackAsync(string sagaLog) { - _logger.LogError("The car reservation has failed starting reverting resources."); + _logger.LogError("The car reservation has failed and all resources are deleted. (Asynchronous Callback)"); _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); - await Task.CompletedTask; - //Option: Send a message to the customer } - private async void OnSuccessCompletionCallbackAsync(string sagaLog) + private async Task OnFailedRevertedCallbackAsync(string sagaLog) { - _logger.LogInformation("The car reservation has succeeded."); - _logger.LogInformation("The car reservation log:" + Environment.NewLine + sagaLog); + _logger.LogError("The car reservation has failed and left some unused resources. (Asynchronous Callback)"); + _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); + await Task.CompletedTask; + } + private async Task OnFailedCallbackAsync(string sagaLog) + { + _logger.LogError("The car reservation has failed starting reverting resources. (Asynchronous Callback)"); + _logger.LogError("The car reservation log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer await Task.CompletedTask; - //Option: Send a message to the customer } private async Task OnSagaCompletedAsync(object? _, SagaCompletionEventArgs e) diff --git a/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservationCancellation/CarReservationCancellationActor.cs b/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservationCancellation/CarReservationCancellationActor.cs index 5afe7a7..f93e508 100644 --- a/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservationCancellation/CarReservationCancellationActor.cs +++ b/Sagaway.ReservationDemo/Sagaway.ReservationDemo.ReservationManager/Actors/CarReservationCancellation/CarReservationCancellationActor.cs @@ -27,10 +27,16 @@ public CarReservationCancellationActor(ActorHost host, ILogger ReBuildSaga() { var saga = Saga.Create(_actorHost.Id.ToString(), this, _logger) - .WithOnSuccessCompletionCallback(OnSuccessCompletionCallbackAsync) - .WithOnRevertedCallback(OnRevertedCallbackAsync) - .WithOnFailedRevertedCallback(OnFailedRevertedCallbackAsync) - .WithOnFailedCallback(OnFailedCallbackAsync) + // Synchronous Callbacks + .WithOnSuccessCompletionCallback(OnSuccessCompletionCallback) + .WithOnRevertedCallback(OnRevertedCallback) + .WithOnFailedRevertedCallback(OnFailedRevertedCallback) + .WithOnFailedCallback(OnFailedCallback) + // Asynchronous Callbacks + .WithOnSuccessCompletionCallbackAsync(OnSuccessCompletionCallbackAsync) + .WithOnRevertedCallbackAsync(OnRevertedCallbackAsync) + .WithOnFailedRevertedCallbackAsync(OnFailedRevertedCallbackAsync) + .WithOnFailedCallbackAsync(OnFailedCallbackAsync) .WithOperation(CarCancelReservationActorOperations.CancelBooking) .WithDoOperation(CancelCarBookingAsync) @@ -356,38 +362,62 @@ await DaprClient.InvokeMethodAsync(HttpMethod.Get, "billing-manage #region Saga Completion Methods - private async void OnFailedRevertedCallbackAsync(string sagaLog) + // Synchronous Callback Methods + private void OnSuccessCompletionCallback(string sagaLog) { - _logger.LogError("The car reservation cancelling has failed and left some unused resources."); + _logger.LogInformation("The car reservation cancelling has succeeded. (Synchronous Callback)"); + _logger.LogInformation("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + } + + private void OnRevertedCallback(string sagaLog) + { + _logger.LogError("The car reservation cancelling has failed and all resources are deleted. (Synchronous Callback)"); _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + } - await Task.CompletedTask; + private void OnFailedRevertedCallback(string sagaLog) + { + _logger.LogError("The car reservation cancelling has failed and left some unused resources. (Synchronous Callback)"); + _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); } - private async void OnRevertedCallbackAsync(string sagaLog) + private void OnFailedCallback(string sagaLog) { - _logger.LogError("The car reservation cancelling has failed and all resources are deleted."); + _logger.LogError("The car reservation cancelling has failed starting reverting resources. (Synchronous Callback)"); _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + } - await Task.CompletedTask; + // Asynchronous Callback Methods + private Task OnSuccessCompletionCallbackAsync(string sagaLog) + { + _logger.LogInformation("The car reservation cancelling has succeeded. (Asynchronous Callback)"); + _logger.LogInformation("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + return Task.CompletedTask; } - private async void OnFailedCallbackAsync(string sagaLog) + private Task OnRevertedCallbackAsync(string sagaLog) { - _logger.LogError("The car reservation cancelling has failed starting reverting resources."); + _logger.LogError("The car reservation cancelling has failed and all resources are deleted. (Asynchronous Callback)"); _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); - - await Task.CompletedTask; - //Option: Send a message to the customer + return Task.CompletedTask; } - private async void OnSuccessCompletionCallbackAsync(string sagaLog) + private Task OnFailedRevertedCallbackAsync(string sagaLog) { - _logger.LogInformation("The car reservation cancelling has succeeded."); - _logger.LogInformation("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + _logger.LogError("The car reservation cancelling has failed and left some unused resources. (Asynchronous Callback)"); + _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + return Task.CompletedTask; + } - await Task.CompletedTask; - //Option: Send a message to the customer + private Task OnFailedCallbackAsync(string sagaLog) + { + _logger.LogError("The car reservation cancelling has failed starting reverting resources. (Asynchronous Callback)"); + _logger.LogError("The car reservation cancelling log:" + Environment.NewLine + sagaLog); + // Optionally, send a message to the customer + return Task.CompletedTask; } private async Task OnSagaCompletedAsync(object? _, SagaCompletionEventArgs e) diff --git a/Sagaway.Tests/ApprovalFiles/test_O1_After_O2_and_O3.approved.txt b/Sagaway.Tests/ApprovalFiles/test_O1_After_O2_and_O3.approved.txt index 72632bb..9b4265f 100644 --- a/Sagaway.Tests/ApprovalFiles/test_O1_After_O2_and_O3.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_O1_After_O2_and_O3.approved.txt @@ -80,7 +80,7 @@ HasRevertValidate: False Calling Op2: Success True Calling Op3: Success True Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op2]: Start Executing Op2 [*time*][Op2]: Op2 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_O1_O2_O3_O5_O4.approved.txt b/Sagaway.Tests/ApprovalFiles/test_O1_O2_O3_O5_O4.approved.txt index a3c7c55..829d7e3 100644 --- a/Sagaway.Tests/ApprovalFiles/test_O1_O2_O3_O5_O4.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_O1_O2_O3_O5_O4.approved.txt @@ -134,7 +134,7 @@ Calling Op2: Success True Calling Op3: Success True Calling Op5: Success True Calling Op4: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_O5_O4_O3_O2_O1.approved.txt b/Sagaway.Tests/ApprovalFiles/test_O5_O4_O3_O2_O1.approved.txt index 7359635..f8ddfd8 100644 --- a/Sagaway.Tests/ApprovalFiles/test_O5_O4_O3_O2_O1.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_O5_O4_O3_O2_O1.approved.txt @@ -134,7 +134,7 @@ Calling Op4: Success True Calling Op3: Success True Calling Op2: Success True Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op5]: Start Executing Op5 [*time*][Op5]: Op5 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each.approved.txt index 71b95e4..27561f0 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each.approved.txt @@ -139,7 +139,7 @@ Calling Op4: Success True Op4 Validate returns True Calling Op5: Success True Op5 Validate returns True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:01 diff --git a/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each_exponential_wait.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each_exponential_wait.approved.txt index 2cc1e74..b46f25a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each_exponential_wait.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_deactivated_each_exponential_wait.approved.txt @@ -139,7 +139,7 @@ Calling Op4: Success True Op4 Validate returns True Calling Op5: Success True Op5 Validate returns True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_five_failfast_on_third.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_failfast_on_third.approved.txt index 1acdfb6..a47c1da 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_failfast_on_third.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_failfast_on_third.approved.txt @@ -133,7 +133,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success True Calling Op3: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success @@ -161,4 +161,5 @@ OnSagaCompleted: Id: test Status: Reverted 5: EndOperation - SagaID: test, Operation: Op2, Outcome: Succeeded 6: StartOperation - SagaID: test, Operation: Op3 7: EndOperation - SagaID: test, Operation: Op3, Outcome: Failed -8: EndSaga - SagaID: test, Outcome: Reverted +8: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +9: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third.approved.txt index 2aa30dd..2fe99d5 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third.approved.txt @@ -133,7 +133,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success True Calling Op3: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third_with_second_done.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third_with_second_done.approved.txt index f8b50e4..aa29b19 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third_with_second_done.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_fast_success_on_third_with_second_done.approved.txt @@ -133,7 +133,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success True Calling Op3: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_five_success.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_success.approved.txt index 9d1e6bf..1cafcf9 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_success.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_success.approved.txt @@ -134,7 +134,7 @@ Calling Op2: Success True Calling Op3: Success True Calling Op4: Success True Calling Op5: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth.approved.txt index e9c8cbf..7547fd5 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth.approved.txt @@ -133,7 +133,7 @@ Calling Op1: Success True Calling Op2: Success True Calling Op3: Success True Calling Op4: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success @@ -174,4 +174,5 @@ OnSagaCompleted: Id: test Status: Reverted 10: StartOperation - SagaID: test, Operation: Op5 11: Exception - SagaID: test, Context: Error when calling Op5, Exception: Throwing exception on call 1 12: EndOperation - SagaID: test, Operation: Op5, Outcome: Failed -13: EndSaga - SagaID: test, Outcome: Reverted +13: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +14: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth_report_failure.approved.txt b/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth_report_failure.approved.txt index 38ad54f..7b0d599 100644 --- a/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth_report_failure.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_five_throw_on_fifth_report_failure.approved.txt @@ -133,7 +133,7 @@ Calling Op1: Success True Calling Op2: Success True Calling Op3: Success True Calling Op4: Success True -OnFailCallback: Fail. +OnFailedCallbackAsync: Fail. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_single_fail_and_exponential_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_fail_and_exponential_retry.approved.txt index c3d6284..624f743 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_fail_and_exponential_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_fail_and_exponential_retry.approved.txt @@ -27,7 +27,7 @@ HasRevertValidate: False Calling Op1: Success False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_fail_and_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_fail_and_retry.approved.txt index a1ca4f1..144b445 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_fail_and_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_fail_and_retry.approved.txt @@ -27,7 +27,7 @@ HasRevertValidate: False Calling Op1: Success False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:10 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_fail_fast_and_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_fail_fast_and_retry.approved.txt index cfe7abf..e32f59b 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_fail_fast_and_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_fail_fast_and_retry.approved.txt @@ -27,7 +27,7 @@ HasRevertValidate: False Set to fail fast Calling Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:10 @@ -42,4 +42,5 @@ OnSagaCompleted: Id: test Status: Reverted 1: StartSaga - SagaID: test, Type: SagaOperations 2: StartOperation - SagaID: test, Operation: Op1 3: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -4: EndSaga - SagaID: test, Outcome: Reverted +4: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +5: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry.approved.txt index 1c35a20..d2e587d 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry.approved.txt @@ -26,7 +26,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Failed. Retries exhausted. @@ -40,4 +40,5 @@ OnSagaCompleted: Id: test Status: Reverted 1: StartSaga - SagaID: test, Type: SagaOperations 2: StartOperation - SagaID: test, Operation: Op1 3: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -4: EndSaga - SagaID: test, Outcome: Reverted +4: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +5: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry_report_failure.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry_report_failure.approved.txt index 70e37e1..b80113f 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry_report_failure.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_fail_no_retry_report_failure.approved.txt @@ -26,7 +26,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success False -OnFailCallback: Fail. +OnFailedCallbackAsync: Fail. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Failed. Retries exhausted. diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_exception.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_exception.approved.txt index 8cac1b2..7cf9b9c 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_exception.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_exception.approved.txt @@ -29,7 +29,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op1: Success True Op1 Validate returns True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false.approved.txt index cbceb5f..6ce35c8 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false.approved.txt @@ -29,7 +29,7 @@ Calling Op1: Success True Op1 Validate returns False Calling Op1: Success True Op1 Validate returns False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 @@ -53,4 +53,5 @@ OnSagaCompleted: Id: test Status: Reverted 3: RetryAttempt - SagaID: test, Operation: Op1, Attempt: 1 4: StartOperation - SagaID: test, Operation: Op1 5: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -6: EndSaga - SagaID: test, Outcome: Reverted +6: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +7: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert.approved.txt index 09cc0e5..4102fba 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert.approved.txt @@ -31,7 +31,7 @@ Calling Op1: Success False Op1 Validate returns False Calling revert for Op1: Success False Calling revert for Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 @@ -63,4 +63,5 @@ OnSagaCompleted: Id: test Status: Reverted 7: RetryAttempt - SagaID: test, Operation: RevertOp1, Attempt: 1 8: StartOperation - SagaID: test, Operation: RevertOp1 9: EndOperation - SagaID: test, Operation: RevertOp1, Outcome: Reverted -10: EndSaga - SagaID: test, Outcome: Reverted +10: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +11: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_exception.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_exception.approved.txt index 58206aa..a7cd56a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_exception.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_exception.approved.txt @@ -35,7 +35,7 @@ Op1 Validate returns False Calling revert for Op1: Success False Calling revert for Op1: Success False Calling revert for Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 @@ -72,4 +72,5 @@ OnSagaCompleted: Id: test Status: Reverted 9: RetryAttempt - SagaID: test, Operation: RevertOp1, Attempt: 2 10: StartOperation - SagaID: test, Operation: RevertOp1 11: EndOperation - SagaID: test, Operation: RevertOp1, Outcome: Reverted -12: EndSaga - SagaID: test, Outcome: Reverted +12: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +13: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_fails.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_fails.approved.txt index 829427f..823889a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_fails.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_false_with_revert_fails.approved.txt @@ -31,7 +31,7 @@ Calling Op1: Success False Op1 Validate returns False Calling revert for Op1: Success False Calling revert for Op1: Success False -OnFailedRevertedCallback: FailedReverted. +OnFailedRevertedCallbackAsync: FailedReverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 @@ -63,4 +63,5 @@ OnSagaCompleted: Id: test Status: RevertFailed 7: RetryAttempt - SagaID: test, Operation: RevertOp1, Attempt: 1 8: StartOperation - SagaID: test, Operation: RevertOp1 9: EndOperation - SagaID: test, Operation: RevertOp1, Outcome: RevertFailed -10: EndSaga - SagaID: test, Outcome: PartiallyReverted +10: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +11: EndSaga - SagaID: test, Outcome: PartiallyReverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_true.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_true.approved.txt index b6fb268..01013dc 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_true.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_long_wait_validate_true.approved.txt @@ -27,7 +27,7 @@ HasRevertValidate: False Calling Op1: Success True Op1 Validate returns True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_success.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_success.approved.txt index 8bc5b5d..e4e0f4d 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_success.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_success.approved.txt @@ -26,7 +26,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception.approved.txt index bb29ef1..a104849 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception.approved.txt @@ -25,7 +25,7 @@ HasRevert: False HasValidate: False HasRevertValidate: False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Error when calling Op1. Error: Throwing exception on call 1. Retry in 00:00:00 seconds @@ -42,4 +42,5 @@ OnSagaCompleted: Id: test Status: Reverted 2: StartOperation - SagaID: test, Operation: Op1 3: Exception - SagaID: test, Context: Error when calling Op1, Exception: Throwing exception on call 1 4: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -5: EndSaga - SagaID: test, Outcome: Reverted +5: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +6: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_exponential_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_exponential_retry.approved.txt index 2cd7f16..53bce8a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_exponential_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_exponential_retry.approved.txt @@ -26,7 +26,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_retry.approved.txt index 9dbe1fc..f975a4a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_and_retry.approved.txt @@ -26,7 +26,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_report_fail.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_report_fail.approved.txt index 0f7ba99..32a675a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_report_fail.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_report_fail.approved.txt @@ -25,7 +25,7 @@ HasRevert: False HasValidate: False HasRevertValidate: False -OnFailCallback: Fail. +OnFailedCallbackAsync: Fail. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Error when calling Op1. Error: Throwing exception on call 1. Retry in 00:00:00 seconds diff --git a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_twice_and_retry_three_times.approved.txt b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_twice_and_retry_three_times.approved.txt index da4f747..c5d665c 100644 --- a/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_twice_and_retry_three_times.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_single_throw_exception_twice_and_retry_three_times.approved.txt @@ -27,7 +27,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_two_both_failed_revert_fails_2_times.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_both_failed_revert_fails_2_times.approved.txt index 0bfa2aa..aee8e4a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_both_failed_revert_fails_2_times.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_both_failed_revert_fails_2_times.approved.txt @@ -55,7 +55,7 @@ Calling Op1: Success False Calling revert for Op1: Success False Calling revert for Op1: Success False Calling revert for Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Failed. Retries exhausted. @@ -83,4 +83,5 @@ OnSagaCompleted: Id: test Status: Reverted 7: RetryAttempt - SagaID: test, Operation: RevertOp1, Attempt: 2 8: StartOperation - SagaID: test, Operation: RevertOp1 9: EndOperation - SagaID: test, Operation: RevertOp1, Outcome: Reverted -10: EndSaga - SagaID: test, Outcome: Reverted +10: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +11: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_first_deactivate_saga.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_first_deactivate_saga.approved.txt index bb0aec7..65512fe 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_first_deactivate_saga.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_first_deactivate_saga.approved.txt @@ -54,7 +54,7 @@ HasRevertValidate: False Calling Op1: Success True Op1 Validate returns True Calling Op2: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:01 diff --git a/Sagaway.Tests/ApprovalFiles/test_two_first_failed_fast_after_running_second.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_first_failed_fast_after_running_second.approved.txt index b9055d9..2e61a47 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_first_failed_fast_after_running_second.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_first_failed_fast_after_running_second.approved.txt @@ -54,7 +54,7 @@ Set to fail fast Calling Op2: Success True Calling Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op2]: Start Executing Op2 [*time*][Op2]: Op2 Success @@ -74,4 +74,5 @@ OnSagaCompleted: Id: test Status: Reverted 3: EndOperation - SagaID: test, Operation: Op2, Outcome: Succeeded 4: StartOperation - SagaID: test, Operation: Op1 5: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -6: EndSaga - SagaID: test, Outcome: Reverted +6: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +7: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_first_fast_succeeded_second_not_run.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_first_fast_succeeded_second_not_run.approved.txt index 3d501fd..004813b 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_first_fast_succeeded_second_not_run.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_first_fast_succeeded_second_not_run.approved.txt @@ -53,7 +53,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry.approved.txt index 69a7c49..e186735 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry.approved.txt @@ -53,7 +53,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success @@ -73,4 +73,5 @@ OnSagaCompleted: Id: test Status: Reverted 3: EndOperation - SagaID: test, Operation: Op1, Outcome: Succeeded 4: StartOperation - SagaID: test, Operation: Op2 5: EndOperation - SagaID: test, Operation: Op2, Outcome: Failed -6: EndSaga - SagaID: test, Outcome: Reverted +6: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +7: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry_report_failure.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry_report_failure.approved.txt index 312e438..dec12ff 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry_report_failure.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_first_success_second_fail_no_retry_report_failure.approved.txt @@ -53,7 +53,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success False -OnFailCallback: Fail. +OnFailedCallbackAsync: Fail. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success diff --git a/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_exception.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_exception.approved.txt index 82d2e54..3918c9b 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_exception.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_exception.approved.txt @@ -28,7 +28,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op1: Success True Op1 Validate returns False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 @@ -53,4 +53,5 @@ OnSagaCompleted: Id: test Status: Reverted 3: RetryAttempt - SagaID: test, Operation: Op1, Attempt: 1 4: StartOperation - SagaID: test, Operation: Op1 5: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -6: EndSaga - SagaID: test, Outcome: Reverted +6: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +7: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_false_with_revert_exception.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_false_with_revert_exception.approved.txt index dfe7c1a..bf79cc2 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_false_with_revert_exception.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_long_wait_validate_false_with_revert_exception.approved.txt @@ -62,7 +62,7 @@ Op2 Validate returns False Calling revert for Op2: Success False Calling revert for Op2: Success False Calling revert for Op2: Success False -OnFailedRevertedCallback: FailedReverted. +OnFailedRevertedCallbackAsync: FailedReverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success @@ -105,4 +105,5 @@ OnSagaCompleted: Id: test Status: RevertFailed 11: RetryAttempt - SagaID: test, Operation: RevertOp2, Attempt: 2 12: StartOperation - SagaID: test, Operation: RevertOp2 13: EndOperation - SagaID: test, Operation: RevertOp2, Outcome: RevertFailed -14: EndSaga - SagaID: test, Outcome: PartiallyReverted +14: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +15: EndSaga - SagaID: test, Outcome: PartiallyReverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_first.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_first.approved.txt index cd2feab..57af7a9 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_first.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_first.approved.txt @@ -51,7 +51,7 @@ HasRevert: False HasValidate: False HasRevertValidate: False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Error when calling Op1. Error: Throwing exception on call 1. Retry in 00:00:00 seconds @@ -69,4 +69,5 @@ OnSagaCompleted: Id: test Status: Reverted 2: StartOperation - SagaID: test, Operation: Op1 3: Exception - SagaID: test, Context: Error when calling Op1, Exception: Throwing exception on call 1 4: EndOperation - SagaID: test, Operation: Op1, Outcome: Failed -5: EndSaga - SagaID: test, Outcome: Reverted +5: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +6: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_second.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_second.approved.txt index 383dcd1..3b2ccd9 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_second.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_ops_throw_exception_on_second.approved.txt @@ -52,7 +52,7 @@ HasValidate: False HasRevertValidate: False Calling Op1: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Op1 Success @@ -75,4 +75,5 @@ OnSagaCompleted: Id: test Status: Reverted 4: StartOperation - SagaID: test, Operation: Op2 5: Exception - SagaID: test, Context: Error when calling Op2, Exception: Throwing exception on call 1 6: EndOperation - SagaID: test, Operation: Op2, Outcome: Failed -7: EndSaga - SagaID: test, Outcome: Reverted +7: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +8: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_depends_on_first.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_depends_on_first.approved.txt index 63d141c..a484809 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_depends_on_first.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_depends_on_first.approved.txt @@ -52,7 +52,7 @@ HasValidate: False HasRevertValidate: False Calling Op2: Success False -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op2]: Start Executing Op2 [*time*][Op2]: Op2 Failed. Retries exhausted. @@ -67,4 +67,5 @@ OnSagaCompleted: Id: test Status: Reverted 1: StartSaga - SagaID: test, Type: SagaOperations 2: StartOperation - SagaID: test, Operation: Op2 3: EndOperation - SagaID: test, Operation: Op2, Outcome: Failed -4: EndSaga - SagaID: test, Outcome: Reverted +4: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +5: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_fast_second.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_fast_second.approved.txt index 6270f41..e56d061 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_fast_second.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_second_failed_first_fast_second.approved.txt @@ -53,7 +53,7 @@ HasValidate: False HasRevertValidate: False Calling Op2: Success True -OnRevertedCallback: Reverted. +OnRevertedCallbackAsync: Reverted. Run Log: [*time*][Op2]: Start Executing Op2 [*time*][Op2]: Op2 Failed Fast. @@ -68,4 +68,5 @@ OnSagaCompleted: Id: test Status: Reverted 1: StartSaga - SagaID: test, Type: SagaOperations 2: StartOperation - SagaID: test, Operation: Op2 3: EndOperation - SagaID: test, Operation: Op2, Outcome: Failed -4: EndSaga - SagaID: test, Outcome: Reverted +4: CustomEvent - SagaID: test, Event: SagaFailure, Properties: None +5: EndSaga - SagaID: test, Outcome: Reverted diff --git a/Sagaway.Tests/ApprovalFiles/test_two_success_after_5_retries.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_success_after_5_retries.approved.txt index a02e439..b425eda 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_success_after_5_retries.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_success_after_5_retries.approved.txt @@ -61,7 +61,7 @@ Calling Op2: Success False Calling Op2: Success False Calling Op2: Success False Calling Op2: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:01 diff --git a/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_and_retry.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_and_retry.approved.txt index dfffa11..f24af5a 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_and_retry.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_and_retry.approved.txt @@ -53,7 +53,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:02 diff --git a/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_twice_and_retry_three_times.approved.txt b/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_twice_and_retry_three_times.approved.txt index 169d2ff..0ecad46 100644 --- a/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_twice_and_retry_three_times.approved.txt +++ b/Sagaway.Tests/ApprovalFiles/test_two_throw_exception_twice_and_retry_three_times.approved.txt @@ -55,7 +55,7 @@ HasRevertValidate: False Calling Op1: Success True Calling Op2: Success True -OnSuccessCompletionCallback: Success. +OnSuccessCompletionCallbackAsync: Success. Run Log: [*time*][Op1]: Start Executing Op1 [*time*][Op1]: Registering reminder Op1:Retry for Op1 with interval 00:00:01 diff --git a/Sagaway.Tests/Tests.cs b/Sagaway.Tests/Tests.cs index cd35c5f..8d506ae 100644 --- a/Sagaway.Tests/Tests.cs +++ b/Sagaway.Tests/Tests.cs @@ -106,8 +106,11 @@ public void TestValidationNoOperation() // ReSharper disable once UnusedVariable var builder = Saga.Create("test", new SagaTestHost(ReminderCallBack), _logger) .WithOnSuccessCompletionCallback(_ => { }) + .WithOnSuccessCompletionCallbackAsync(_ => Task.CompletedTask) .WithOnRevertedCallback(_ => { }) + .WithOnRevertedCallbackAsync(_ => Task.CompletedTask) .WithOnFailedRevertedCallback(_ => { }) + .WithOnFailedRevertedCallbackAsync(_ => Task.CompletedTask) .Build(); } catch (Exception ex) @@ -128,7 +131,9 @@ public void TestValidationNoOnSuccessCompletionCallback() // ReSharper disable once UnusedVariable var builder = Saga.Create("test", new SagaTestHost(ReminderCallBack), _logger) .WithOnRevertedCallback(_ => { }) + .WithOnRevertedCallbackAsync(_ => Task.CompletedTask) .WithOnFailedRevertedCallback(_ => { }) + .WithOnFailedRevertedCallbackAsync(_ => Task.CompletedTask) .WithOperation(Operations.Op1) .WithDoOperation(() => Task.CompletedTask) .Build(); @@ -151,7 +156,9 @@ public void TestValidationNoOnRevertedCallback() // ReSharper disable once UnusedVariable var builder = Saga.Create("test", new SagaTestHost(ReminderCallBack), _logger) .WithOnSuccessCompletionCallback(_ => { }) + .WithOnSuccessCompletionCallbackAsync(_ => Task.CompletedTask) .WithOnFailedRevertedCallback(_ => { }) + .WithOnFailedRevertedCallbackAsync(_ => Task.CompletedTask) .WithOperation(Operations.Op1) .WithDoOperation(() => Task.CompletedTask) .Build(); @@ -174,7 +181,9 @@ public void TestValidationNoOnFailedRevertedCallback() // ReSharper disable once UnusedVariable var builder = Saga.Create("test", new SagaTestHost(ReminderCallBack), _logger) .WithOnSuccessCompletionCallback(_ => { }) + .WithOnSuccessCompletionCallbackAsync(_ => Task.CompletedTask) .WithOnRevertedCallback(_ => { }) + .WithOnRevertedCallbackAsync(_ => Task.CompletedTask) .WithOperation(Operations.Op1) .WithDoOperation(() => Task.CompletedTask) .Build(); @@ -197,8 +206,11 @@ public void TestValidationOperationNoDoOperation() // ReSharper disable once UnusedVariable var builder = Saga.Create("test", new SagaTestHost(ReminderCallBack), _logger) .WithOnSuccessCompletionCallback(_ => { }) + .WithOnSuccessCompletionCallbackAsync(_ => Task.CompletedTask) .WithOnRevertedCallback(_ => { }) + .WithOnRevertedCallbackAsync(_ => Task.CompletedTask) .WithOnFailedRevertedCallback(_ => { }) + .WithOnFailedRevertedCallbackAsync(_ => Task.CompletedTask) .WithOperation(Operations.Op1) .Build(); } @@ -291,18 +303,54 @@ private async Task TestRunAsync(string testName, params string[] operations) var sb = new StringBuilder(); sb.AppendLine($"Preparing test {testName}"); - builder.WithOnSuccessCompletionCallback(log => sb.AppendLine($"OnSuccessCompletionCallback: Success.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine)); + // Register both synchronous and asynchronous callbacks with sb.AppendLine included directly + builder + .WithOnSuccessCompletionCallback(log => + { + sb.AppendLine($"OnSuccessCompletionCallback: Success.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + }) + .WithOnSuccessCompletionCallbackAsync(async log => + { + sb.AppendLine($"OnSuccessCompletionCallbackAsync: Success.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + await Task.CompletedTask; // If no asynchronous operation, use Task.CompletedTask + }); var buildOperations = BuildTestOperations(operations).ToList(); if (buildOperations.Any(o => o.HasReportFail)) { - builder.WithOnFailedCallback(log => sb.AppendLine($"OnFailCallback: Fail.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine)); - } + builder + .WithOnFailedCallback(log => + { + sb.AppendLine($"OnFailedCallback: Fail.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + }) + .WithOnFailedCallbackAsync(async log => + { + sb.AppendLine($"OnFailedCallbackAsync: Fail.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + await Task.CompletedTask; + }); + } else { - builder.WithOnRevertedCallback(log => sb.AppendLine($"OnRevertedCallback: Reverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine)) - .WithOnFailedRevertedCallback(log => sb.AppendLine($"OnFailedRevertedCallback: FailedReverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine)); + builder + .WithOnRevertedCallback(log => + { + sb.AppendLine($"OnRevertedCallback: Reverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + }) + .WithOnRevertedCallbackAsync(async log => + { + sb.AppendLine($"OnRevertedCallbackAsync: Reverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + await Task.CompletedTask; + }) + .WithOnFailedRevertedCallback(log => + { + sb.AppendLine($"OnFailedRevertedCallback: FailedReverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + }) + .WithOnFailedRevertedCallbackAsync(async log => + { + sb.AppendLine($"OnFailedRevertedCallbackAsync: FailedReverted.{Environment.NewLine}Run Log:{Environment.NewLine}" + log + Environment.NewLine); + await Task.CompletedTask; + }); } foreach (var testOperation in buildOperations) diff --git a/Sagaway/Saga.cs b/Sagaway/Saga.cs index 7c81134..fa86726 100644 --- a/Sagaway/Saga.cs +++ b/Sagaway/Saga.cs @@ -19,9 +19,13 @@ public partial class Saga : ISagaReset, ISaga where private ILogger _logger; private readonly ISagaSupport _sagaSupportOperations; private readonly Action? _onSuccessCallback; + private readonly Func? _onSuccessCallbackAsync; private readonly Action? _onFailedCallback; + private readonly Func? _onFailedCallbackAsync; private readonly Action? _onRevertedCallback; + private readonly Func? _onRevertedCallbackAsync; private readonly Action? _onRevertFailureCallback; + private readonly Func? _onRevertFailureCallbackAsync; private bool _deactivated; private readonly ILockWrapper _lock; private bool _resetSagaState; @@ -166,8 +170,8 @@ public async Task RecordTelemetryExceptionAsync(Exception exception, string? con #endregion //telemetry private Saga(ILogger logger, string sagaUniqueId, ISagaSupport sagaSupportOperations, - IReadOnlyList operations, Action? onSuccessCallback, Action? onFailedCallback, - Action? onRevertedCallback, Action? onRevertFailureCallback) + IReadOnlyList operations, Action? onSuccessCallback, Func? onSuccessCallbackAsync, Action? onFailedCallback, + Func? onFailedCallbackAsync, Action? onRevertedCallback, Func? onRevertedCallbackAsync, Action? onRevertFailureCallback,Func? onRevertFailureCallbackAsync) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -175,9 +179,13 @@ private Saga(ILogger logger, string sagaUniqueId, ISagaSupport sagaSupportOperat _sagaSupportOperations = sagaSupportOperations; _operations = operations.Select(o => new SagaOperationExecution(this, o, logger)).ToList(); _onSuccessCallback = onSuccessCallback; + _onSuccessCallbackAsync = onSuccessCallbackAsync; _onFailedCallback = onFailedCallback; + _onFailedCallbackAsync = onFailedCallbackAsync; _onRevertedCallback = onRevertedCallback; + _onRevertedCallbackAsync = onRevertedCallbackAsync; _onRevertFailureCallback = onRevertFailureCallback; + _onRevertFailureCallbackAsync = onRevertFailureCallbackAsync; _lock = _sagaSupportOperations.CreateLock(); _logger.LogInformation("Created new Saga instance with ID {SagaId}", _sagaUniqueId); @@ -623,12 +631,21 @@ private async Task CheckForCompletionAsync() { //Failed is a transient state, so the saga is not done reverting, //We ensure that we call the onFailedCallback only once - if (Failed && _onFailedCallback != null && !_hasFailedReported) + if (Failed && !_hasFailedReported) { _logger.LogDebug("Saga {_sagaUniqueId} failed, calling onFailedCallback.", _sagaUniqueId); _hasFailedReported = true; - _onFailedCallback(recordedSteps); + + if (_onFailedCallbackAsync != null) + { + await _onFailedCallbackAsync(recordedSteps); + } + else if (_onFailedCallback != null) + { + _onFailedCallback(recordedSteps); + } + await TelemetryAdapter.RecordCustomEventAsync(_telemetryContext, "SagaFailure"); } @@ -643,23 +660,44 @@ private async Task CheckForCompletionAsync() } //first handle completion notification - if (Succeeded && _onSuccessCallback != null) + if (Succeeded) { _logger.LogTrace("Saga {_sagaUniqueId} is succeeded, calling onSuccessCallback.", _sagaUniqueId); - _onSuccessCallback(recordedSteps); + if (_onSuccessCallbackAsync != null) + { + await _onSuccessCallbackAsync(recordedSteps); + } + else if (_onSuccessCallback != null) + { + _onSuccessCallback(recordedSteps); + } } - else if (Reverted && _onRevertedCallback != null) + else if (Reverted) { _logger.LogTrace("Saga {_sagaUniqueId} is reverted, calling onRevertedCallback.", _sagaUniqueId); - _onRevertedCallback(recordedSteps); + if (_onRevertedCallbackAsync != null) + { + await _onRevertedCallbackAsync(recordedSteps); + } + else if (_onRevertedCallback != null) + { + _onRevertedCallback(recordedSteps); + } } - else if (RevertFailed && _onRevertFailureCallback != null) + else if (RevertFailed) { _logger.LogTrace("Saga {_sagaUniqueId} is revert failed, calling onRevertFailureCallback.", _sagaUniqueId); - _onRevertFailureCallback(recordedSteps); + if (_onRevertFailureCallbackAsync != null) + { + await _onRevertFailureCallbackAsync(recordedSteps); + } + else if (_onRevertFailureCallback != null) + { + _onRevertFailureCallback(recordedSteps); + } } } catch (Exception ex) diff --git a/Sagaway/Sagaway.Builder/SagaBuilder.cs b/Sagaway/Sagaway.Builder/SagaBuilder.cs index 68bfcf7..988de0d 100644 --- a/Sagaway/Sagaway.Builder/SagaBuilder.cs +++ b/Sagaway/Sagaway.Builder/SagaBuilder.cs @@ -14,10 +14,15 @@ public partial class SagaBuilder private readonly ISagaSupport _sagaSupportOperations; private readonly ILogger _logger; private Action? _onSuccessCompletionCallback; + private Func? _onSuccessCompletionCallbackAsync; private Action? _onRevertedCallback; + private Func? _onRevertedCallbackAsync; private Action? _onFailedRevertedCallback; - private readonly List _operations = new(); + private Func? _onFailedRevertedCallbackAsync; private Action? _onFailedCallback; + private Func? _onFailedCallbackAsync; + private readonly List _operations = new(); + /// /// The saga fluent interface builder @@ -43,6 +48,16 @@ public SagaBuilder WithOnSuccessCompletionCallback(Action onSuccessCompl return this; } + /// + /// Add an asynchronous action that is called on success completion of the saga + /// + /// The asynchronous callback function. Receives the complete saga log + /// The saga builder for fluent build + public SagaBuilder WithOnSuccessCompletionCallbackAsync(Func onSuccessCompletionCallbackAsync) + { + _onSuccessCompletionCallbackAsync = onSuccessCompletionCallbackAsync; + return this; + } /// /// Add an action that is called on a failure of the saga before any compensation is handle, if exists @@ -55,6 +70,17 @@ public SagaBuilder WithOnFailedCallback(Action onFailedCallback) return this; } + /// + /// Add an asynchronous action that is called on a failure of the saga before any compensation is handled, if exists + /// + /// The asynchronous callback function. Receives the partial saga log + /// The saga builder for fluent build + public SagaBuilder WithOnFailedCallbackAsync(Func onFailedCallbackAsync) + { + _onFailedCallbackAsync = onFailedCallbackAsync; + return this; + } + /// /// Add an action that is called on a failure of the saga after all compensations (reverts) are done /// @@ -68,6 +94,19 @@ public SagaBuilder WithOnRevertedCallback(Action onRevertedCallback) return this; } + /// + /// Add an asynchronous action that is called on a failure of the saga after all compensations (reverts) are done + /// + /// The asynchronous callback function. Receives the complete saga log + /// The saga builder for fluent build + /// At least one operation failed, all retries are done. + /// The Saga has finished the compensation (revert) process + public SagaBuilder WithOnRevertedCallbackAsync(Func onRevertedCallbackAsync) + { + _onRevertedCallbackAsync = onRevertedCallbackAsync; + return this; + } + /// /// Add an action that is called on a failure in reverting the saga when doing compensations /// @@ -81,6 +120,19 @@ public SagaBuilder WithOnFailedRevertedCallback(Action onFailedRevertedC return this; } + /// + /// Add an asynchronous action that is called on a failure in reverting the saga when doing compensations + /// + /// The asynchronous callback function. Receives the saga log + /// The saga builder for fluent build + /// At least one operation failed, all retries are done, but at least one operation failed to revert. + /// The Saga has finished the compensation (revert) process + public SagaBuilder WithOnFailedRevertedCallbackAsync(Func onFailedRevertedCallbackAsync) + { + _onFailedRevertedCallbackAsync = onFailedRevertedCallbackAsync; + return this; + } + /// /// Add an operation to the saga /// @@ -102,7 +154,19 @@ private void AddOperation(SagaOperation operation) /// The saga instance public ISaga Build() { - var saga = new Saga(_logger, _sagaUniqueId, _sagaSupportOperations, _operations, _onSuccessCompletionCallback, _onFailedCallback ,_onRevertedCallback, _onFailedRevertedCallback); + var saga = new Saga( + _logger, + _sagaUniqueId, + _sagaSupportOperations, + _operations, + _onSuccessCompletionCallback, + _onSuccessCompletionCallbackAsync, + _onFailedCallback, + _onFailedCallbackAsync, + _onRevertedCallback, + _onRevertedCallbackAsync, + _onFailedRevertedCallback, + _onFailedRevertedCallbackAsync); return saga; } }