Skip to content

Commit 759f652

Browse files
committed
docs: readme
1 parent 05d7e30 commit 759f652

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,35 @@ defmodule MyApp.OrderWorkflow do
5353
use Durable
5454
use Durable.Context
5555

56-
workflow "process_order" do
57-
step :charge, retry: [max_attempts: 3, backoff: :exponential] do
58-
{:ok, charge} = Payments.charge(input().order)
56+
workflow "process_order", timeout: hours(2) do
57+
step :validate do
58+
order = input().order
59+
put_context(:order_id, order.id)
60+
put_context(:items, order.items)
61+
end
62+
63+
step :calculate_total do
64+
total =
65+
get_context(:items)
66+
|> Enum.map(& &1.price)
67+
|> Enum.sum()
68+
69+
put_context(:total, total)
70+
end
71+
72+
step :charge_payment, retry: [max_attempts: 3, backoff: :exponential] do
73+
{:ok, charge} = PaymentService.charge(get_context(:order_id), get_context(:total))
5974
put_context(:charge_id, charge.id)
6075
end
6176

62-
step :notify do
63-
Mailer.send_receipt(input().email, get_context(:charge_id))
77+
step :send_confirmation do
78+
EmailService.send_confirmation(get_context(:order_id))
6479
end
6580
end
6681
end
6782

6883
# Start it
69-
{:ok, id} = Durable.start(MyApp.OrderWorkflow, %{order: order, email: "user@example.com"})
84+
{:ok, id} = Durable.start(MyApp.OrderWorkflow, %{order: order})
7085
```
7186

7287
## Examples

0 commit comments

Comments
 (0)