-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathOrderFlow2.cs
More file actions
41 lines (34 loc) · 1.36 KB
/
Copy pathOrderFlow2.cs
File metadata and controls
41 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Cleipnir.ResilientFunctions.Domain;
namespace Cleipnir.Flows.Sample.Presentation.Solutions.A_OrderFlowRpc;
public class OrderFlow2 : Flow<Order>
{
private readonly IPaymentProviderClient _paymentProviderClient;
private readonly IEmailClient _emailClient;
private readonly ILogisticsClient _logisticsClient;
public OrderFlow2(IPaymentProviderClient paymentProviderClient, IEmailClient emailClient, ILogisticsClient logisticsClient)
{
_paymentProviderClient = paymentProviderClient;
_emailClient = emailClient;
_logisticsClient = logisticsClient;
}
public override async Task Run(Order order)
{
var transactionId = await Effect.Capture("TransactionId", Guid.NewGuid);
await _paymentProviderClient.Reserve(order.CustomerId, transactionId, order.TotalPrice);
try
{
await Effect.Capture(
"ShipProducts",
work: () => _logisticsClient.ShipProducts(order.CustomerId, order.ProductIds),
ResiliencyLevel.AtMostOnce
);
}
catch (Exception)
{
await _paymentProviderClient.CancelReservation(transactionId);
throw;
}
await _paymentProviderClient.Capture(transactionId);
await _emailClient.SendOrderConfirmation(order.CustomerId, order.ProductIds);
}
}