Skip to content

Commit fcb11bc

Browse files
committed
feat: update wait_for_callback examples for new submitter signature
Update all wait_for_callback example submitter functions to accept the new WaitForCallbackContext parameter. The SDK changed the submitter signature from `submitter(callback_id: str)` to `submitter(callback_id: str, context: WaitForCallbackContext)`. Changes: - Add WaitForCallbackContext import where needed - Update all submitter function signatures to include context param - Update lambda submitters to accept both callback_id and context - Use underscore prefix for unused context parameters Affected examples: - wait_for_callback.py - wait_for_callback_anonymous.py - wait_for_callback_child.py - wait_for_callback_heartbeat.py - wait_for_callback_mixed_ops.py - wait_for_callback_multiple_invocations.py - wait_for_callback_nested.py - wait_for_callback_serdes.py - wait_for_callback_submitter_failure.py - wait_for_callback_submitter_failure_catchable.py - wait_for_callback_timeout.py
1 parent 3e3c29d commit fcb11bc

11 files changed

+35
-30
lines changed

examples/src/wait_for_callback/wait_for_callback.py

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

3-
from aws_durable_execution_sdk_python.config import WaitForCallbackConfig
4-
from aws_durable_execution_sdk_python.context import DurableContext
3+
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
4+
from aws_durable_execution_sdk_python.context import (
5+
DurableContext,
6+
WaitForCallbackContext,
7+
)
58
from aws_durable_execution_sdk_python.execution import durable_execution
6-
from aws_durable_execution_sdk_python.config import Duration
79

810

9-
def external_system_call(_callback_id: str) -> None:
11+
def external_system_call(_callback_id: str, _context: WaitForCallbackContext) -> None:
1012
"""Simulate calling an external system with callback ID."""
1113
# In real usage, this would make an API call to an external system
1214
# passing the callback_id for the system to call back when done

examples/src/wait_for_callback/wait_for_callback_anonymous.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
@durable_execution
1111
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
1212
"""Handler demonstrating waitForCallback with anonymous submitter."""
13-
result: str = context.wait_for_callback(lambda _: time.sleep(1))
13+
result: str = context.wait_for_callback(
14+
lambda _callback_id, _context: time.sleep(1)
15+
)
1416

1517
return {
1618
"callbackResult": result,

examples/src/wait_for_callback/wait_for_callback_child.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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,
89
)
910
from aws_durable_execution_sdk_python.execution import durable_execution
10-
from aws_durable_execution_sdk_python.config import Duration
1111

1212

1313
@durable_with_child_context
@@ -16,7 +16,7 @@ def child_context_with_callback(child_context: DurableContext) -> dict[str, Any]
1616
child_context.wait(Duration.from_seconds(1), name="child-wait")
1717

1818
child_callback_result: str = child_context.wait_for_callback(
19-
lambda _: None, name="child-callback-op"
19+
lambda _callback_id, _context: None, name="child-callback-op"
2020
)
2121

2222
return {
@@ -29,7 +29,7 @@ def child_context_with_callback(child_context: DurableContext) -> dict[str, Any]
2929
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
3030
"""Handler demonstrating waitForCallback within child contexts."""
3131
parent_result: str = context.wait_for_callback(
32-
lambda _: None, name="parent-callback-op"
32+
lambda _callback_id, _context: None, name="parent-callback-op"
3333
)
3434

3535
child_context_result: dict[str, Any] = context.run_in_child_context(

examples/src/wait_for_callback/wait_for_callback_heartbeat.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import time
44
from typing import Any
55

6-
from aws_durable_execution_sdk_python.context import DurableContext
6+
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
7+
from aws_durable_execution_sdk_python.context import (
8+
DurableContext,
9+
WaitForCallbackContext,
10+
)
711
from aws_durable_execution_sdk_python.execution import durable_execution
8-
from aws_durable_execution_sdk_python.config import Duration
9-
from aws_durable_execution_sdk_python.config import WaitForCallbackConfig
1012

1113

12-
def submitter(_callback_id: str) -> None:
14+
def submitter(_callback_id: str, _context: WaitForCallbackContext) -> None:
1315
"""Simulate long-running submitter function."""
1416
time.sleep(5)
1517
return None

examples/src/wait_for_callback/wait_for_callback_mixed_ops.py

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

6+
from aws_durable_execution_sdk_python.config import Duration
67
from aws_durable_execution_sdk_python.context import DurableContext
78
from aws_durable_execution_sdk_python.execution import durable_execution
8-
from aws_durable_execution_sdk_python.config import Duration
99

1010

1111
@durable_execution
@@ -19,7 +19,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
1919
name="fetch-user-data",
2020
)
2121

22-
def submitter(_) -> None:
22+
def submitter(_callback_id, _context) -> None:
2323
"""Submitter uses data from previous step."""
2424
time.sleep(0.1)
2525
return None

examples/src/wait_for_callback/wait_for_callback_multiple_invocations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
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
7-
from aws_durable_execution_sdk_python.config import Duration
88

99

1010
@durable_execution
@@ -14,7 +14,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
1414
context.wait(Duration.from_seconds(1), name="wait-invocation-1")
1515

1616
# First callback operation
17-
def first_submitter(callback_id: str) -> None:
17+
def first_submitter(callback_id: str, _context) -> None:
1818
"""Submitter for first callback."""
1919
print(f"First callback submitted with ID: {callback_id}")
2020
return None
@@ -34,7 +34,7 @@ def first_submitter(callback_id: str) -> None:
3434
context.wait(Duration.from_seconds(1), name="wait-invocation-2")
3535

3636
# Second callback operation
37-
def second_submitter(callback_id: str) -> None:
37+
def second_submitter(callback_id: str, _context) -> None:
3838
"""Submitter for second callback."""
3939
print(f"Second callback submitted with ID: {callback_id}")
4040
return None

examples/src/wait_for_callback/wait_for_callback_nested.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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,
89
)
910
from aws_durable_execution_sdk_python.execution import durable_execution
10-
from aws_durable_execution_sdk_python.config import Duration
1111

1212

1313
@durable_with_child_context
@@ -16,7 +16,7 @@ def inner_child_context(inner_child_ctx: DurableContext) -> dict[str, Any]:
1616
inner_child_ctx.wait(Duration.from_seconds(5), name="deep-wait")
1717

1818
nested_callback_result: str = inner_child_ctx.wait_for_callback(
19-
lambda _: None,
19+
lambda _callback_id, _context: None,
2020
name="nested-callback-op",
2121
)
2222

@@ -30,7 +30,7 @@ def inner_child_context(inner_child_ctx: DurableContext) -> dict[str, Any]:
3030
def outer_child_context(outer_child_ctx: DurableContext) -> dict[str, Any]:
3131
"""Outer child context with inner callback and nested context."""
3232
inner_result: str = outer_child_ctx.wait_for_callback(
33-
lambda _: None,
33+
lambda _callback_id, _context: None,
3434
name="inner-callback-op",
3535
)
3636

@@ -51,7 +51,7 @@ def outer_child_context(outer_child_ctx: DurableContext) -> dict[str, Any]:
5151
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
5252
"""Handler demonstrating nested waitForCallback operations across multiple levels."""
5353
outer_result: str = context.wait_for_callback(
54-
lambda _: None,
54+
lambda _callback_id, _context: None,
5555
name="outer-callback-op",
5656
)
5757

examples/src/wait_for_callback/wait_for_callback_serdes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from datetime import datetime
55
from typing import Any, Optional, TypedDict
66

7+
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
78
from aws_durable_execution_sdk_python.context import DurableContext
89
from aws_durable_execution_sdk_python.execution import durable_execution
9-
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
1010
from aws_durable_execution_sdk_python.serdes import SerDes
1111

1212

@@ -75,7 +75,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
7575
)
7676

7777
result: CustomData = context.wait_for_callback(
78-
lambda _: None,
78+
lambda _callback_id, _context: None,
7979
name="custom-serdes-callback",
8080
config=config,
8181
)

examples/src/wait_for_callback/wait_for_callback_submitter_failure.py

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

33
from typing import Any
44

5+
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
56
from aws_durable_execution_sdk_python.context import DurableContext
67
from aws_durable_execution_sdk_python.execution import durable_execution
78
from aws_durable_execution_sdk_python.retries import (
89
RetryStrategyConfig,
910
create_retry_strategy,
1011
)
11-
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
1212

1313

1414
@durable_execution
1515
def handler(event: dict[str, Any], context: DurableContext) -> dict[str, Any]:
1616
"""Handler demonstrating waitForCallback with submitter retry and exponential backoff."""
1717

18-
def submitter(callback_id: str) -> None:
18+
def submitter(callback_id: str, _context) -> None:
1919
"""Submitter function that can fail based on event parameter."""
2020
print(f"Submitting callback to external system - callbackId: {callback_id}")
2121
raise Exception("Simulated submitter failure")

examples/src/wait_for_callback/wait_for_callback_submitter_failure_catchable.py

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

6+
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
67
from aws_durable_execution_sdk_python.context import DurableContext
78
from aws_durable_execution_sdk_python.execution import durable_execution
89
from aws_durable_execution_sdk_python.retries import (
910
RetryStrategyConfig,
1011
create_retry_strategy,
1112
)
12-
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
1313

1414

1515
@durable_execution
1616
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
1717
"""Handler demonstrating waitForCallback with failing submitter."""
1818

19-
def submitter(_) -> None:
19+
def submitter(_callback_id, _context) -> None:
2020
"""Submitter function that fails after a delay."""
2121
time.sleep(0.5)
2222
# Submitter fails

0 commit comments

Comments
 (0)