fix: Fix EfTxBehavior for save persist-message

This commit is contained in:
Pc 2023-06-04 13:55:04 +03:30
parent 7e9cea74f6
commit cc710292a3
3 changed files with 9 additions and 7 deletions

View File

@ -195,6 +195,9 @@ dotnet_separate_import_directive_groups = false
dotnet_style_namespace_match_folder = false
dotnet_diagnostic.IDE0130.severity = none
[*.{cs,vb}]
dotnet_diagnostic.CA1305.severity = none
# C# formatting rules
# https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#c-formatting-rules
[*.{cs,csx,cake}]

View File

@ -79,13 +79,11 @@ public class EfTxBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TRe
});
// Save data to database with some retry policy in distributed transaction
await _dbContextBase.RetryOnFailure(async () =>
await _persistMessageDbContext.RetryOnFailure(async () =>
{
await _dbContextBase.SaveChangesAsync(cancellationToken);
await _persistMessageDbContext.SaveChangesAsync(cancellationToken);
});
await _persistMessageDbContext.SaveChangesAsync(cancellationToken);
scope.Complete();
return response;

View File

@ -1,6 +1,7 @@
namespace BuildingBlocks.Polly;
using global::Polly;
using Serilog;
using Exception = System.Exception;
public static class Extensions
@ -9,10 +10,10 @@ public static class Extensions
{
var retryPolicy = Policy
.Handle<Exception>()
.Retry(retryCount, (exception, retryAttempt) =>
.Retry(retryCount, (exception, retryAttempt, context) =>
{
Console.WriteLine($"Retry attempt: {retryAttempt}");
Console.WriteLine($"Exception: {exception.Message}");
Log.Information($"Retry attempt: {retryAttempt}");
Log.Error($"Exception: {exception.Message}");
});
return retryPolicy.Execute(action);