Skip to content

Commit c77182c

Browse files
author
Alex Wang
committed
test(examples): add wait and handler error test examples
- Add testing examples - wait for condition - handler error - Update wait example with Duration change - Update web runner and workflow, only warning on error response so that we can test on funciton exception
1 parent 74a4bf2 commit c77182c

File tree

22 files changed

+142
-60
lines changed

22 files changed

+142
-60
lines changed

.github/workflows/deploy-examples.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ jobs:
158158
# Check for function errors
159159
FUNCTION_ERROR=$(jq -r '.FunctionError // empty' /tmp/invoke_response.json)
160160
if [ -n "$FUNCTION_ERROR" ]; then
161-
echo "ERROR: Lambda function failed with error: $FUNCTION_ERROR"
161+
echo "Warning: Lambda function failed with error: $FUNCTION_ERROR"
162162
echo "Function response:"
163163
cat /tmp/response.json
164-
exit 1
165164
fi
166165
167166
# Extract invocation ID from response headers

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dist/
2929
.kiro/
3030
.idea
3131
.env
32+
.env*
3233

3334
.durable_executions
3435

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ from durable_executions_python_language_sdk.context import (
3838
durable_with_child_context,
3939
)
4040
from durable_executions_python_language_sdk.execution import durable_execution
41+
from aws_durable_execution_sdk_python.config import Duration
42+
4143

4244
@durable_step
4345
def one(a: int, b: int) -> str:
@@ -68,7 +70,7 @@ def function_under_test(event: Any, context: DurableContext) -> list[str]:
6870
result_one: str = context.step(one(1, 2))
6971
results.append(result_one)
7072

71-
context.wait(seconds=1)
73+
context.wait(Duration.from_seconds(1))
7274

7375
result_two: str = context.run_in_child_context(two(3, 4))
7476
results.append(result_two)

examples/examples-catalog.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,17 @@
297297
"ExecutionTimeout": 300
298298
},
299299
"path": "./src/parallel/parallel_with_batch_serdes.py"
300+
},
301+
{
302+
"name": "Handler Error",
303+
"description": "Simple function with handler error",
304+
"handler": "handler_error.handler",
305+
"integration": true,
306+
"durableConfig": {
307+
"RetentionPeriodInDays": 7,
308+
"ExecutionTimeout": 300
309+
},
310+
"path": "./src/handler_error/handler_error.py"
300311
}
301312
]
302313
}

examples/src/block_example/block_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
durable_with_child_context,
88
)
99
from aws_durable_execution_sdk_python.execution import durable_execution
10+
from aws_durable_execution_sdk_python.config import Duration
1011

1112

1213
@durable_with_child_context
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from aws_durable_execution_sdk_python.config import CallbackConfig
44
from aws_durable_execution_sdk_python.context import DurableContext
55
from aws_durable_execution_sdk_python.execution import durable_execution
6+
from aws_durable_execution_sdk_python.config import Duration
67

78

89
if TYPE_CHECKING:
@@ -11,7 +12,9 @@
1112

1213
@durable_execution
1314
def handler(_event: Any, context: DurableContext) -> str:
14-
callback_config = CallbackConfig(timeout_seconds=120, heartbeat_timeout_seconds=60)
15+
callback_config = CallbackConfig(
16+
timeout=Duration.from_seconds(120), heartbeat_timeout=Duration.from_seconds(60)
17+
)
1518

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

examples/src/callback/callback_with_timeout.py

Lines changed: 4 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,9 @@
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(
16+
timeout=Duration.from_seconds(60), heartbeat_timeout=Duration.from_seconds(30)
17+
)
1618

1719
callback: Callback[str] = context.create_callback(
1820
name="timeout_callback", config=config
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Demonstrates how handler-level errors are captured and structured in results."""
2+
3+
from typing import Any
4+
5+
from aws_durable_execution_sdk_python.context import DurableContext
6+
from aws_durable_execution_sdk_python.execution import durable_execution
7+
8+
9+
@durable_execution
10+
def handler(_event: Any, _context: DurableContext) -> None:
11+
"""Handler demonstrating handler-level error capture."""
12+
# Simulate a handler-level error that might occur in real applications
13+
raise Exception("Intentional handler failure")

examples/src/parallel/parallel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from aws_durable_execution_sdk_python.config import ParallelConfig
66
from aws_durable_execution_sdk_python.context import DurableContext
77
from aws_durable_execution_sdk_python.execution import durable_execution
8+
from aws_durable_execution_sdk_python.config import Duration
89

910

1011
@durable_execution
@@ -17,7 +18,7 @@ def handler(_event: Any, context: DurableContext) -> list[str]:
1718
lambda ctx: ctx.step(lambda _: "task 1 completed", name="task1"),
1819
lambda ctx: ctx.step(lambda _: "task 2 completed", name="task2"),
1920
lambda ctx: (
20-
ctx.wait(1, name="wait_in_task3"),
21+
ctx.wait(Duration.from_seconds(1), name="wait_in_task3"),
2122
"task 3 completed after wait",
2223
)[1],
2324
],

examples/src/parallel/parallel_with_wait.py

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

55
from aws_durable_execution_sdk_python.context import DurableContext
66
from aws_durable_execution_sdk_python.execution import durable_execution
7+
from aws_durable_execution_sdk_python.config import Duration
78

89

910
@durable_execution
@@ -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()

0 commit comments

Comments
 (0)