File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed
Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 188188 },
189189 "path" : " ./src/wait_for_callback/wait_for_callback_serdes.py"
190190 },
191+ {
192+ "name" : " Wait For Callback Timeout" ,
193+ "description" : " Usage of context.wait_for_callback() to wait for external system responses" ,
194+ "handler" : " wait_for_callback_timeout.handler" ,
195+ "integration" : true ,
196+ "durableConfig" : {
197+ "RetentionPeriodInDays" : 7 ,
198+ "ExecutionTimeout" : 300
199+ },
200+ "path" : " ./src/wait_for_callback/wait_for_callback_timeout.py"
201+ },
191202 {
192203 "name" : " Wait For Callback Nested" ,
193204 "description" : " Usage of context.wait_for_callback() to wait for external system responses" ,
Original file line number Diff line number Diff line change 1+ """Demonstrates waitForCallback timeout scenarios."""
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+ from aws_durable_execution_sdk_python .config import Duration
8+ from aws_durable_execution_sdk_python .config import WaitForCallbackConfig
9+
10+
11+ @durable_execution
12+ def handler (_event : Any , context : DurableContext ) -> dict [str , Any ]:
13+ """Handler demonstrating waitForCallback timeout."""
14+
15+ config = WaitForCallbackConfig (
16+ timeout = Duration .from_seconds (1 ), heartbeat_timeout = Duration .from_seconds (2 )
17+ )
18+
19+ def submitter (_ ) -> None :
20+ """Submitter succeeds but callback never completes."""
21+ return None
22+
23+ try :
24+ result : str = context .wait_for_callback (
25+ submitter ,
26+ config = config ,
27+ )
28+
29+ return {
30+ "callbackResult" : result ,
31+ "success" : True ,
32+ }
33+ except Exception as error :
34+ return {
35+ "success" : False ,
36+ "error" : str (error ),
37+ }
Original file line number Diff line number Diff line change @@ -254,6 +254,20 @@ Resources:
254254 DurableConfig :
255255 RetentionPeriodInDays : 7
256256 ExecutionTimeout : 300
257+ WaitForCallbackTimeout :
258+ Type : AWS::Serverless::Function
259+ Properties :
260+ CodeUri : build/
261+ Handler : wait_for_callback_timeout.handler
262+ Description : Usage of context.wait_for_callback() to wait for external system
263+ responses
264+ Role :
265+ Fn::GetAtt :
266+ - DurableFunctionRole
267+ - Arn
268+ DurableConfig :
269+ RetentionPeriodInDays : 7
270+ ExecutionTimeout : 300
257271 WaitForCallbackNested :
258272 Type : AWS::Serverless::Function
259273 Properties :
Original file line number Diff line number Diff line change 1+ """Tests for wait_for_callback_timeout."""
2+
3+ import pytest
4+ from aws_durable_execution_sdk_python .execution import InvocationStatus
5+
6+ from src .wait_for_callback import wait_for_callback_timeout
7+ from test .conftest import deserialize_operation_payload
8+
9+
10+ @pytest .mark .example
11+ @pytest .mark .durable_execution (
12+ handler = wait_for_callback_timeout .handler ,
13+ lambda_function_name = "Wait For Callback Timeout" ,
14+ )
15+ def test_handle_wait_for_callback_timeout_scenarios (durable_runner ):
16+ """Test waitForCallback timeout scenarios."""
17+ test_payload = {"test" : "timeout-scenario" }
18+
19+ with durable_runner :
20+ execution_arn = durable_runner .run_async (input = test_payload , timeout = 30 )
21+ # Don't send callback - let it timeout
22+ result = durable_runner .wait_for_result (execution_arn = execution_arn )
23+
24+ # Handler catches the timeout error, so execution succeeds with error in result
25+ assert result .status is InvocationStatus .SUCCEEDED
26+
27+ result_data = deserialize_operation_payload (result .result )
28+
29+ assert result_data ["success" ] is False
30+ assert isinstance (result_data ["error" ], str )
31+ assert len (result_data ["error" ]) > 0
32+ assert "Callback timed out" == result_data ["error" ]
You can’t perform that action at this time.
0 commit comments