Skip to content

Commit 93a1f53

Browse files
embano1yaythomas
authored andcommitted
docs: fix duration format in examples
Closes: #253 Signed-off-by: Michael Gasch <15986659+embano1@users.noreply.github.com>
1 parent f835016 commit 93a1f53

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

docs/best-practices.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ context.create_callback(name="payment_callback")
343343
context.create_callback(name="approval_callback")
344344

345345
# Pattern: descriptive_wait for waits
346-
context.wait(seconds=30, name="payment_confirmation_wait")
346+
context.wait(Duration.from_seconds(30), name="payment_confirmation_wait")
347347
```
348348

349349
### Name dynamic operations with context
@@ -494,7 +494,7 @@ Only use waits when you need to delay execution:
494494
@durable_execution
495495
def lambda_handler(event: dict, context: DurableContext) -> dict:
496496
job_id = context.step(start_job(event["data"]))
497-
context.wait(seconds=30, name="job_processing_wait") # Necessary
497+
context.wait(Duration.from_seconds(30), name="job_processing_wait") # Necessary
498498
result = context.step(check_job_status(job_id))
499499
return result
500500
```
@@ -609,7 +609,7 @@ def lambda_handler(event: dict, context: DurableContext) -> dict:
609609
@durable_step
610610
def process_with_wait(step_context: StepContext, context: DurableContext) -> str:
611611
# DON'T: Can't use context inside its own step operation
612-
context.wait(seconds=1) # Error: using context inside step!
612+
context.wait(Duration.from_seconds(1)) # Error: using context inside step!
613613
result = context.step(nested_step(), name="step2") # Error: nested context.step!
614614
return result
615615

docs/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def handler(event: dict, context: DurableContext) -> dict:
7272
data = context.step(fetch_data(event["id"]))
7373

7474
# Step 2: Wait 30 seconds
75-
context.wait(seconds=30)
75+
context.wait(Duration.from_seconds(30))
7676

7777
# Step 3: Process the data
7878
result = context.step(process_data(data))
@@ -85,15 +85,15 @@ def handler(event: dict, context: DurableContext) -> dict:
8585
1. Lambda invokes your function
8686
2. `fetch_data` executes and calls an external API
8787
3. Result is checkpointed to AWS
88-
4. `context.wait(seconds=30)` is reached
88+
4. `context.wait(Duration.from_seconds(30))` is reached
8989
5. Function returns, Lambda can recycle the environment
9090

9191
**Second invocation (t=30s):**
9292

9393
1. Lambda invokes your function again
9494
2. Function code runs from the beginning
9595
3. `fetch_data` returns the checkpointed result instantly (no API call)
96-
4. `context.wait(seconds=30)` is already complete, execution continues
96+
4. `context.wait(Duration.from_seconds(30))` is already complete, execution continues
9797
5. `process_data` executes for the first time
9898
6. Result is checkpointed
9999
7. Function returns the final result

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ from aws_durable_execution_sdk_python import (
5555
durable_execution,
5656
durable_step,
5757
)
58+
from aws_durable_execution_sdk_python.config import Duration
5859

5960
@durable_step
6061
def validate_order(order_id: str) -> dict:
@@ -86,7 +87,7 @@ def process_order(event: dict, context: DurableContext) -> dict:
8687
payment = context.step(charge_payment(order_id, amount))
8788

8889
# Step 3: Wait for payment confirmation (simulated)
89-
context.wait(seconds=5)
90+
context.wait(Duration.from_seconds(5))
9091

9192
# Step 4: Fulfill the order
9293
fulfillment = context.step(fulfill_order(order_id))

docs/testing-patterns/basic-tests.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,11 @@ Here's a function with a wait:
311311

312312
```python
313313
from aws_durable_execution_sdk_python import DurableContext, durable_execution
314+
from aws_durable_execution_sdk_python.config import Duration
314315

315316
@durable_execution
316317
def handler(event: dict, context: DurableContext) -> str:
317-
context.wait(seconds=5)
318+
context.wait(Duration.from_seconds(5))
318319
return "Wait completed"
319320
```
320321

docs/testing-patterns/complex-workflows.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def handler(event: dict, context: DurableContext) -> str:
121121

122122
if amount > 1000:
123123
context.step(lambda _: "Manager approval required", name="approval")
124-
context.wait(seconds=10, name="approval_wait")
124+
context.wait(Duration.from_seconds(10), name="approval_wait")
125125
result = context.step(lambda _: "High-value order processed", name="process_high")
126126
else:
127127
result = context.step(lambda _: "Standard order processed", name="process_standard")
@@ -514,7 +514,7 @@ For workflows with long waits, verify configuration without actually waiting:
514514
@durable_execution
515515
def handler(event: dict, context: DurableContext) -> str:
516516
context.step(lambda _: "Starting", name="start")
517-
context.wait(seconds=3600, name="long_wait") # 1 hour
517+
context.wait(Duration.from_seconds(3600), name="long_wait") # 1 hour
518518
context.step(lambda _: "Continuing", name="continue")
519519
return "Complete"
520520
```
@@ -559,7 +559,7 @@ def handler(event: dict, context: DurableContext) -> int:
559559
if state >= 3:
560560
break
561561

562-
context.wait(seconds=1, name=f"wait_{attempt}")
562+
context.wait(Duration.from_seconds(1), name=f"wait_{attempt}")
563563

564564
return state
565565
```
@@ -604,7 +604,7 @@ def handler(event: dict, context: DurableContext) -> dict:
604604
state = context.step(lambda _, s=state: s + 1, name=f"attempt_{attempt}")
605605

606606
if state < target:
607-
context.wait(seconds=1, name=f"wait_{attempt}")
607+
context.wait(Duration.from_seconds(1), name=f"wait_{attempt}")
608608

609609
return {"state": state, "attempts": attempt, "reached_target": state >= target}
610610
```

0 commit comments

Comments
 (0)