Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions TransactionProcessor.BusinessLogic/Common/PolicyFactory.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Threading.Tasks;
using EventStore.Client;
using EventStore.Client;
using Grpc.Core;
using Polly;
using Polly.Fallback;
using Polly.Retry;
using Polly.Wrap;
using Shared.Logger;
using SimpleResults;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace TransactionProcessor.BusinessLogic.Common;

Expand All @@ -29,10 +30,17 @@ public static async Task<Result> ExecuteWithPolicyAsync(Func<Task<Result>> actio
{
var context = new Context();
context["RetryCount"] = 0;
//Result result = await policy.ExecuteAsync(action);

Result result = await policy.ExecuteAsync((ctx) => action(), context);

int retryCount = (int)context["RetryCount"];
String message = result.IsSuccess ? "Execution succeeded." : $"Execution failed with error: {result.Message}";
String message = result switch
{
{ IsSuccess: true } => "Success",
{ IsSuccess: false, Message: not "" } => result.Message,
{ IsSuccess: false, Message: "", Errors: var errors } when errors.Any() => string.Join(", ", errors),
_ => "Unknown Error"
};
String retryMessage = retryCount > 0 ? $" after {retryCount} retries." : "";
// Log success if no retries were required

Expand Down
Loading