File tree Expand file tree Collapse file tree 3 files changed +13
-28
lines changed
Expand file tree Collapse file tree 3 files changed +13
-28
lines changed Original file line number Diff line number Diff line change 2929.kiro /
3030.idea
3131.env
32+ .env *
3233
3334.durable_executions
3435
Original file line number Diff line number Diff line change 44
55from aws_durable_execution_sdk_python .context import DurableContext
66from aws_durable_execution_sdk_python .execution import durable_execution
7+ from aws_durable_execution_sdk_python .waits import WaitForConditionConfig
78
89
910@durable_execution
1011def 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
Original file line number Diff line number Diff line change 22
33import pytest
44from aws_durable_execution_sdk_python .execution import InvocationStatus
5- from aws_durable_execution_sdk_python .lambda_service import OperationType
65
76from src .wait_for_condition import wait_for_condition
87from 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
You can’t perform that action at this time.
0 commit comments