mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-14 12:48:34 +08:00
fix: Fix EfTxBehavior for save persist-message
This commit is contained in:
parent
7e9cea74f6
commit
cc710292a3
@ -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}]
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user