Skip to content

Commit 29cb5bf

Browse files
author
Alex Wang
committed
test(examples): update wait for condition example
1 parent 74a4bf2 commit 29cb5bf

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

.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

examples/src/wait_for_condition/wait_for_condition.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@
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.waits import WaitForConditionConfig
78

89

910
@durable_execution
1011
def handler(_event: Any, context: DurableContext) -> int:
1112
"""Handler demonstrating wait-for-condition pattern."""
12-
state = 0
13-
attempt = 0
14-
max_attempts = 5
1513

16-
while attempt < max_attempts:
17-
attempt += 1
14+
def condition_function(state: int) -> int:
15+
"""Increment state by 1."""
16+
return state + 1
1817

19-
# Execute step to update state
20-
state = context.step(
21-
lambda _, s=state: s + 1,
22-
name=f"increment_state_{attempt}",
23-
)
24-
25-
# Check condition
18+
def wait_strategy(state: int, attempt: int) -> dict[str, Any]:
19+
"""Wait strategy that continues until state reaches 3."""
2620
if state >= 3:
27-
# Condition met, stop
28-
break
21+
return {"shouldContinue": False}
22+
return {"shouldContinue": True, "delay_seconds": 1}
23+
24+
config = WaitForConditionConfig(wait_strategy=wait_strategy, initial_state=0)
2925

30-
# Wait before next attempt
31-
context.wait(seconds=1)
26+
result = context.wait_for_condition(check=condition_function, config=config)
3227

33-
return state
28+
return result

examples/test/wait_for_condition/test_wait_for_condition.py

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

33
import pytest
44
from aws_durable_execution_sdk_python.execution import InvocationStatus
5-
from aws_durable_execution_sdk_python.lambda_service import OperationType
65

76
from src.wait_for_condition import wait_for_condition
87
from test.conftest import deserialize_operation_payload
@@ -21,13 +20,3 @@ def test_wait_for_condition(durable_runner):
2120
assert result.status is InvocationStatus.SUCCEEDED
2221
# Should reach state 3 after 3 increments
2322
assert deserialize_operation_payload(result.result) == 3
24-
25-
# Verify step operations exist (should have 3 increment steps)
26-
step_ops = [
27-
op for op in result.operations if op.operation_type == OperationType.STEP
28-
]
29-
assert len(step_ops) == 3
30-
31-
# Verify wait operations exist (should have 2 waits before final state)
32-
wait_ops = [op for op in result.operations if op.operation_type.value == "WAIT"]
33-
assert len(wait_ops) == 2

0 commit comments

Comments
 (0)