SimplCommerce
SimplCommerce copied to clipboard
MySqlRetryingExecutionStrategy
Hello community, I have the follo error at .develop custom payment provider. When insert one order fail de transaction in the order service.
Call Order Service from payment provider
Order Service File
Error
does this issue is fixed ? should I work on this issue
Seems it's still there
I solved this issue with
await ResilientTransaction.New(db).ExecuteAsync(async () => { _orderRepository.SaveChanges(); await PublishOrderCreatedEvent(order); foreach (var subOrder in subOrders) { await PublishOrderCreatedEvent(subOrder); }
_couponService.AddCouponUsage(cart.CustomerId, order.Id, checkingDiscountResult);
_orderRepository.SaveChanges();
});
public class ResilientTransaction
{
private DbContext _context;
private ResilientTransaction(DbContext context) =>
_context = context ?? throw new ArgumentNullException(nameof(context));
public static ResilientTransaction New(DbContext context) =>
new ResilientTransaction(context);
public async Task ExecuteAsync(Func<Task> action)
{
// Use of an EF Core resiliency strategy when using multiple DbContexts
// within an explicit BeginTransaction():
// https://docs.microsoft.com/ef/core/miscellaneous/connection-resiliency
var strategy = _context.Database.CreateExecutionStrategy();
await strategy.ExecuteAsync(async () =>
{
using (var transaction = _context.Database.BeginTransaction())
{
await action();
transaction.Commit();
}
});
}
}
Could you please submit a PR?