Skip to content

Commit 9cd1957

Browse files
committed
Update all examples to use Duration API
- Replace context.wait(seconds=N) with context.wait(Duration.from_seconds(N)) - Replace CallbackConfig(timeout_seconds=N) with CallbackConfig(timeout=Duration.from_seconds(N)) - Replace WaitForCallbackConfig timeout_seconds/heartbeat_timeout_seconds with Duration objects - Replace RetryStrategyConfig initial_delay_seconds/max_delay_seconds with Duration objects - Add Duration import to all affected files - Aligns with Duration refactoring in main SDK
1 parent 08ebf4c commit 9cd1957

File tree

13 files changed

+29
-22
lines changed

13 files changed

+29
-22
lines changed

examples/src/block_example/block_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any
44

5+
from aws_durable_execution_sdk_python.config import Duration
56
from aws_durable_execution_sdk_python.context import (
67
DurableContext,
78
durable_with_child_context,
@@ -13,7 +14,7 @@
1314
def nested_block(ctx: DurableContext) -> str:
1415
"""Nested block with its own child context."""
1516
# Wait in the nested block
16-
ctx.wait(seconds=1)
17+
ctx.wait(Duration.from_seconds(1))
1718
return "nested block result"
1819

1920

examples/src/callback/callback.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, Any
22

3-
from aws_durable_execution_sdk_python.config import CallbackConfig
3+
from aws_durable_execution_sdk_python.config import CallbackConfig, Duration
44
from aws_durable_execution_sdk_python.context import DurableContext
55
from aws_durable_execution_sdk_python.execution import durable_execution
66

@@ -11,7 +11,7 @@
1111

1212
@durable_execution
1313
def handler(_event: Any, context: DurableContext) -> str:
14-
callback_config = CallbackConfig(timeout_seconds=120, heartbeat_timeout_seconds=60)
14+
callback_config = CallbackConfig(timeout=Duration.from_minutes(2), heartbeat_timeout=Duration.from_minutes(1))
1515

1616
callback: Callback[str] = context.create_callback(
1717
name="example_callback", config=callback_config

examples/src/callback/callback_with_timeout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, Any
22

3-
from aws_durable_execution_sdk_python.config import CallbackConfig
3+
from aws_durable_execution_sdk_python.config import CallbackConfig, Duration
44
from aws_durable_execution_sdk_python.context import DurableContext
55
from aws_durable_execution_sdk_python.execution import durable_execution
66

@@ -12,7 +12,7 @@
1212
@durable_execution
1313
def handler(_event: Any, context: DurableContext) -> str:
1414
# Callback with custom timeout configuration
15-
config = CallbackConfig(timeout_seconds=60, heartbeat_timeout_seconds=30)
15+
config = CallbackConfig(timeout=Duration.from_minutes(1), heartbeat_timeout=Duration.from_seconds(30))
1616

1717
callback: Callback[str] = context.create_callback(
1818
name="timeout_callback", config=config

examples/src/parallel/parallel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any
44

5-
from aws_durable_execution_sdk_python.config import ParallelConfig
5+
from aws_durable_execution_sdk_python.config import Duration, ParallelConfig
66
from aws_durable_execution_sdk_python.context import DurableContext
77
from aws_durable_execution_sdk_python.execution import durable_execution
88

@@ -17,7 +17,7 @@ def handler(_event: Any, context: DurableContext) -> list[str]:
1717
lambda ctx: ctx.step(lambda _: "task 1 completed", name="task1"),
1818
lambda ctx: ctx.step(lambda _: "task 2 completed", name="task2"),
1919
lambda ctx: (
20-
ctx.wait(1, name="wait_in_task3"),
20+
ctx.wait(Duration.from_seconds(1), name="wait_in_task3"),
2121
"task 3 completed after wait",
2222
)[1],
2323
],

examples/src/parallel/parallel_with_wait.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any
44

5+
from aws_durable_execution_sdk_python.config import Duration
56
from aws_durable_execution_sdk_python.context import DurableContext
67
from aws_durable_execution_sdk_python.execution import durable_execution
78

@@ -13,9 +14,9 @@ def handler(_event: Any, context: DurableContext) -> str:
1314
# Call get_results() to extract data and avoid BatchResult serialization
1415
context.parallel(
1516
functions=[
16-
lambda ctx: ctx.wait(1, name="wait_1_second"),
17-
lambda ctx: ctx.wait(2, name="wait_2_seconds"),
18-
lambda ctx: ctx.wait(5, name="wait_5_seconds"),
17+
lambda ctx: ctx.wait(Duration.from_seconds(1), name="wait_1_second"),
18+
lambda ctx: ctx.wait(Duration.from_seconds(2), name="wait_2_seconds"),
19+
lambda ctx: ctx.wait(Duration.from_seconds(5), name="wait_5_seconds"),
1920
],
2021
name="parallel_waits",
2122
).get_results()

examples/src/run_in_child_context/run_in_child_context_large_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Any
44

5+
from aws_durable_execution_sdk_python.config import Duration
56
from aws_durable_execution_sdk_python.context import (
67
DurableContext,
78
durable_with_child_context,
@@ -55,7 +56,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
5556
)
5657

5758
# Add a wait after runInChildContext to test persistence across invocations
58-
context.wait(seconds=1, name="post-processing-wait")
59+
context.wait(Duration.from_seconds(1), name="post-processing-wait")
5960

6061
# Verify the data is still intact after the wait
6162
data_integrity_check = (

examples/src/step/step_with_exponential_backoff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from aws_durable_execution_sdk_python.config import StepConfig
3+
from aws_durable_execution_sdk_python.config import Duration, StepConfig
44
from aws_durable_execution_sdk_python.context import DurableContext
55
from aws_durable_execution_sdk_python.execution import durable_execution
66
from aws_durable_execution_sdk_python.retries import (
@@ -13,7 +13,7 @@
1313
def handler(_event: Any, context: DurableContext) -> str:
1414
# Step with exponential backoff retry strategy
1515
retry_config = RetryStrategyConfig(
16-
max_attempts=3, initial_delay_seconds=1, max_delay_seconds=10, backoff_rate=2.0
16+
max_attempts=3, initial_delay=Duration.from_seconds(1), max_delay=Duration.from_seconds(10), backoff_rate=2.0
1717
)
1818

1919
step_config = StepConfig(retry_strategy=create_retry_strategy(retry_config))

examples/src/step/steps_with_retry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from random import random
44
from typing import Any
55

6-
from aws_durable_execution_sdk_python.config import StepConfig
6+
from aws_durable_execution_sdk_python.config import Duration, StepConfig
77
from aws_durable_execution_sdk_python.context import DurableContext
88
from aws_durable_execution_sdk_python.execution import durable_execution
99
from aws_durable_execution_sdk_python.retries import (
@@ -60,7 +60,7 @@ def handler(event: Any, context: DurableContext) -> dict[str, Any]:
6060
break
6161

6262
# Wait 1 second until next poll
63-
context.wait(seconds=1)
63+
context.wait(Duration.from_seconds(1))
6464

6565
except RuntimeError as e:
6666
# Retries exhausted

examples/src/wait/multiple_wait.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
from typing import Any
44

5+
from aws_durable_execution_sdk_python.config import Duration
56
from aws_durable_execution_sdk_python.context import DurableContext
67
from aws_durable_execution_sdk_python.execution import durable_execution
78

89

910
@durable_execution
1011
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
1112
"""Handler demonstrating multiple sequential wait operations."""
12-
context.wait(seconds=5, name="wait-1")
13-
context.wait(seconds=5, name="wait-2")
13+
context.wait(Duration.from_seconds(5), name="wait-1")
14+
context.wait(Duration.from_seconds(5), name="wait-2")
1415

1516
return {
1617
"completedWaits": 2,

examples/src/wait/wait.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Any
22

3+
from aws_durable_execution_sdk_python.config import Duration
34
from aws_durable_execution_sdk_python.context import DurableContext
45
from aws_durable_execution_sdk_python.execution import durable_execution
56

67

78
@durable_execution
89
def handler(_event: Any, context: DurableContext) -> str:
9-
context.wait(seconds=5)
10+
context.wait(Duration.from_seconds(5))
1011
return "Wait completed"

0 commit comments

Comments
 (0)