@@ -7,6 +7,7 @@ internal sealed class OrderWorkflow : Workflow<Order, OrderStatus>
77{
88 public override async Task < OrderStatus > RunAsync ( WorkflowContext context , Order order )
99 {
10+ // First two independent activities are called in parallel (fan-out/fan-in pattern):
1011 var inventoryTask = context . CallActivityAsync < ActivityResult > (
1112 nameof ( CheckInventory ) ,
1213 order . OrderItem ) ;
@@ -22,6 +23,8 @@ public override async Task<OrderStatus> RunAsync(WorkflowContext context, Order
2223 return new OrderStatus ( IsSuccess : false , message ) ;
2324 }
2425
26+ // Two activities are called in sequence (chaining pattern) where the UpdateInventory
27+ // activity is dependent on the result of the ProcessPayment activity:
2528 var paymentResult = await context . CallActivityAsync < PaymentResult > (
2629 nameof ( ProcessPayment ) ,
2730 order ) ;
@@ -35,22 +38,26 @@ public override async Task<OrderStatus> RunAsync(WorkflowContext context, Order
3538 ShipmentRegistrationStatus shipmentRegistrationStatus ;
3639 try
3740 {
41+ // The RegisterShipment activity is using pub/sub messaging to communicate with the ShippingApp.
3842 await context . CallActivityAsync < RegisterShipmentResult > (
3943 nameof ( RegisterShipment ) ,
4044 order ) ;
45+ // The ShippingApp will also use pub/sub messaging back to the WorkflowApp and raise an event.
46+ // The workflow will wait for the event to be received or until the timeout occurs.
4147 shipmentRegistrationStatus = await context . WaitForExternalEventAsync < ShipmentRegistrationStatus > (
4248 eventName : Constants . SHIPMENT_REGISTERED_EVENT ,
4349 timeout : TimeSpan . FromSeconds ( 300 ) ) ;
4450 }
4551 catch ( TaskCanceledException )
4652 {
47- // Timeout occurred
53+ // Timeout occurred, the shipment-registered-event was not received.
4854 var message = $ "ShipmentRegistrationStatus for { order . Id } timed out.";
4955 return new OrderStatus ( IsSuccess : false , message ) ;
5056 }
5157
5258 if ( ! shipmentRegistrationStatus . IsSuccess )
5359 {
60+ // This is the compensation step in case the shipment registration event was not successful.
5461 await context . CallActivityAsync (
5562 nameof ( ReimburseCustomer ) ,
5663 order ) ;
0 commit comments