Skip to content

Commit

Permalink
Improved MessageDrivenOrderFlow sample for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Oct 6, 2024
1 parent 4051c92 commit 952e0b1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven.Other;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Reactive.Extensions;

namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven;

public class MessageDrivenOrderFlow(Bus bus) : Flow<Order>
{
public override async Task Run(Order order)
{
//todo throw OrderProcessingException
var transactionId = await Capture(Guid.NewGuid);

await ReserveFunds(order, transactionId);
Expand All @@ -24,14 +27,26 @@ private Task ReserveFunds(Order order, Guid transactionId)
=> Capture(
() => bus.Send(new ReserveFunds(order.OrderId, order.TotalPrice, transactionId, order.CustomerId))
);
private Task CancelFundsReservation(Order order, Guid transactionId)
=> Capture(
() => bus.Send(new CancelFundsReservation(order.OrderId, transactionId))
);
private Task ShipProducts(Order order)
=> Capture(
() => bus.Send(new ShipProducts(order.OrderId, order.CustomerId, order.ProductIds))
);
private Task CancelProductsShipment(Order order)
=> Capture(
() => bus.Send(new CancelProductsShipment(order.OrderId))
);
private Task CaptureFunds(Order order, Guid transactionId)
=> Capture(
() => bus.Send(new CaptureFunds(order.OrderId, order.CustomerId, transactionId))
);
private Task ReverseTransaction(Order order, Guid transactionId)
=> Capture(
() => bus.Send(new ReverseTransaction(order.OrderId, transactionId))
);
private Task SendOrderConfirmationEmail(Order order, string trackAndTraceNumber)
=> Capture(
() => bus.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId, trackAndTraceNumber))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Cleipnir.Flows.Sample.MicrosoftOpen.Flows.MessageDriven;

public class OrderProcessingException : Exception
{
public OrderProcessingException(string message) : base(message) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public record FundsReservationFailed(string OrderId) : EventsAndCommands;
public record FundsCaptureFailed(string OrderId) : EventsAndCommands;
public record ProductsShipmentFailed(string OrderId) : EventsAndCommands;
public record OrderConfirmationEmailFailed(string OrderId) : EventsAndCommands;
public record CancelProductShipment(string OrderId) : EventsAndCommands;
public record CancelProductsShipment(string OrderId) : EventsAndCommands;
public record ReverseTransaction(string OrderId, Guid TransactionId) : EventsAndCommands;
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private Task CaptureFunds(Order order, Guid transactionId)
private Task SendOrderConfirmationEmail(Order order, ProductsShipped productsShipped)
=> Capture(() => bus.Send(new SendOrderConfirmationEmail(order.OrderId, order.CustomerId, productsShipped.TrackAndTraceNumber)));
private Task CancelProductsShipment(Order order)
=> Capture(() => bus.Send(new CancelProductShipment(order.OrderId)));
=> Capture(() => bus.Send(new CancelProductsShipment(order.OrderId)));
private Task CancelFundsReservation(Order order, Guid transactionId)
=> Capture(() => bus.Send(new CancelFundsReservation(order.OrderId, transactionId)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ await Effect.Capture(
.Where(e => e.Match(taken => taken.Iteration, rejected => rejected.Iteration) == i)
.FirstOrNone();

if (!option.HasValue && option.Value.AsObject() is SupportTicketTaken)
if (!option.HasNone && option.AsObject() is SupportTicketTaken)
return; //ticket was taken in iteration i
}
}
Expand Down

0 comments on commit 952e0b1

Please sign in to comment.