fulfillment v1

examples/fulfillment/temporal/fulfillment.flow · dandori doc

Reserve stock for each line of an order, arrange the delivery, wait for the warehouse to pack it, and then tell the customer. The lines are reserved side by side, and when one is short, what was reserved is released. Written for Temporal: the warehouse's calls are activities dandori writes, by Connect; a workflow of the delivery team, on its own task queue, arranges the delivery (a child workflow, arrange_delivery.flow), and when it finds no next-day van the standard carrier is asked; and the packing request, the notice and the audit log are activities you write, the packing crew answering the callback by the update the generated client sends

flow
let results = for line in order.lines at most 50 in parallel, 10 at a timeyield rfor one in results at most 50for taken in results at most 50 in parallelevery round doneshortsecuredafter the last itemtruesome idnoneevery round donefalsesome giftsome wordsnonenoneon NoVanon failureon failureon timeouton no_recipientfulfillment v173 decision = urgency(…)rule urgency.ruletimeout, failure → the workflow fails!75 r = reserve_stock(…)connect warehouse StockService/Reserveretry 2 times every 1 second on busybusy, timeout, failure → the round fails, and then the workflow!77 let any_short = false79 match one.stock80 let any_short = true82 match any_short85 match taken.id86 release_stock(…)connect warehouse StockService/Releasetimeout, failure → the round fails, and then the workflow!88 fail OutOfStock"Order {order.id} has lines the stock is short …90 let recipient = none91 match order.gift93 let recipient = gift.recipient94 match gift.message95 audit(…)a task you writetimeout, failure → the workflow fails!98 delivery = arrange_delivery(…)flow arrange_delivery.flow100 delivery = arrange_delivery(…)flow arrange_delivery.flow101 fail DeliveryFailed"Could not arrange the delivery of order {order…102 fail DeliveryFailed"Could not arrange the delivery of order {order…103 packed = wait_for_packing(…)a task you write, answered by a callbacktimeout 2 daystimeout → line 104; failure → the workflow fails!104 fail PackingLate"No word of the packing in two days"105 notify(…)a task you writeno_recipient → line 106; timeout, failure → the workflow fails!107 succeed reservations = results, tracking_number = deliv…

Calls

LineCallCallsRetriesTimeoutWhen it fails
73decision = urgency(…)rule urgency.rule2 times, after 1 second and 2 (failure)—timeout, failure → the workflow fails
75r = reserve_stock(…)connect warehouse StockService/Reserve, key2 times every 1 second (busy)—busy, timeout, failure → the round fails, and then the workflow
86release_stock(…)connect warehouse StockService/Release, idempotent——timeout, failure → the round fails, and then the workflow
95audit(…)a task you write, idempotent——timeout, failure → the workflow fails
98delivery = arrange_delivery(…)flow arrange_delivery.flow——NoVan → line 99
timeout, failure → line 102
100delivery = arrange_delivery(…)flow arrange_delivery.flow——NoVan, timeout, failure → line 101
103packed = wait_for_packing(…)a task you write, answered by a callback—2 daystimeout → line 104
failure → the workflow fails
105notify(…)a task you write——no_recipient → line 106
timeout, failure → the workflow fails

Ends

LineEnd
88fail OutOfStock "Order {order.id} has lines the stock is short of"
101fail DeliveryFailed "Could not arrange the delivery of order {order.id}"
102fail DeliveryFailed "Could not arrange the delivery of order {order.id}"
104fail PackingLate "No word of the packing in two days"
107succeed reservations = results, tracking_number = delivery.tracking_number