Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ context.create_callback(name="payment_callback")
context.create_callback(name="approval_callback")

# Pattern: descriptive_wait for waits
context.wait(seconds=30, name="payment_confirmation_wait")
context.wait(Duration.from_seconds(30), name="payment_confirmation_wait")
```

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

Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def handler(event: dict, context: DurableContext) -> dict:
data = context.step(fetch_data(event["id"]))

# Step 2: Wait 30 seconds
context.wait(seconds=30)
context.wait(Duration.from_seconds(30))

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

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

1. Lambda invokes your function again
2. Function code runs from the beginning
3. `fetch_data` returns the checkpointed result instantly (no API call)
4. `context.wait(seconds=30)` is already complete, execution continues
4. `context.wait(Duration.from_seconds(30))` is already complete, execution continues
5. `process_data` executes for the first time
6. Result is checkpointed
7. Function returns the final result
Expand Down
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ from aws_durable_execution_sdk_python import (
durable_execution,
durable_step,
)
from aws_durable_execution_sdk_python.config import Duration

@durable_step
def validate_order(order_id: str) -> dict:
Expand Down Expand Up @@ -86,7 +87,7 @@ def process_order(event: dict, context: DurableContext) -> dict:
payment = context.step(charge_payment(order_id, amount))

# Step 3: Wait for payment confirmation (simulated)
context.wait(seconds=5)
context.wait(Duration.from_seconds(5))

# Step 4: Fulfill the order
fulfillment = context.step(fulfill_order(order_id))
Expand Down
3 changes: 2 additions & 1 deletion docs/testing-patterns/basic-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,11 @@ Here's a function with a wait:

```python
from aws_durable_execution_sdk_python import DurableContext, durable_execution
from aws_durable_execution_sdk_python.config import Duration

@durable_execution
def handler(event: dict, context: DurableContext) -> str:
context.wait(seconds=5)
context.wait(Duration.from_seconds(5))
return "Wait completed"
```

Expand Down
8 changes: 4 additions & 4 deletions docs/testing-patterns/complex-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def handler(event: dict, context: DurableContext) -> str:

if amount > 1000:
context.step(lambda _: "Manager approval required", name="approval")
context.wait(seconds=10, name="approval_wait")
context.wait(Duration.from_seconds(10), name="approval_wait")
result = context.step(lambda _: "High-value order processed", name="process_high")
else:
result = context.step(lambda _: "Standard order processed", name="process_standard")
Expand Down Expand Up @@ -514,7 +514,7 @@ For workflows with long waits, verify configuration without actually waiting:
@durable_execution
def handler(event: dict, context: DurableContext) -> str:
context.step(lambda _: "Starting", name="start")
context.wait(seconds=3600, name="long_wait") # 1 hour
context.wait(Duration.from_seconds(3600), name="long_wait") # 1 hour
context.step(lambda _: "Continuing", name="continue")
return "Complete"
```
Expand Down Expand Up @@ -559,7 +559,7 @@ def handler(event: dict, context: DurableContext) -> int:
if state >= 3:
break

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

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

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

return {"state": state, "attempts": attempt, "reached_target": state >= target}
```
Expand Down
Loading