Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/src/wait_for_callback/wait_for_callback.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from typing import Any

from aws_durable_execution_sdk_python.config import WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import (
DurableContext,
WaitForCallbackContext,
)
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration


def external_system_call(_callback_id: str) -> None:
def external_system_call(_callback_id: str, _context: WaitForCallbackContext) -> None:
"""Simulate calling an external system with callback ID."""
# In real usage, this would make an API call to an external system
# passing the callback_id for the system to call back when done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
@durable_execution
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
"""Handler demonstrating waitForCallback with anonymous submitter."""
result: str = context.wait_for_callback(lambda _: time.sleep(1))
result: str = context.wait_for_callback(
lambda _callback_id, _context: time.sleep(1)
)

return {
"callbackResult": result,
Expand Down
6 changes: 3 additions & 3 deletions examples/src/wait_for_callback/wait_for_callback_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import Any

from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.context import (
DurableContext,
durable_with_child_context,
)
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration


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

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

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

child_context_result: dict[str, Any] = context.run_in_child_context(
Expand Down
10 changes: 6 additions & 4 deletions examples/src/wait_for_callback/wait_for_callback_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import time
from typing import Any

from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import (
DurableContext,
WaitForCallbackContext,
)
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.config import WaitForCallbackConfig


def submitter(_callback_id: str) -> None:
def submitter(_callback_id: str, _context: WaitForCallbackContext) -> None:
"""Simulate long-running submitter function."""
time.sleep(5)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import time
from typing import Any

from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration


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

def submitter(_) -> None:
def submitter(_callback_id, _context) -> None:
"""Submitter uses data from previous step."""
time.sleep(0.1)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from typing import Any

from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration


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

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

# Second callback operation
def second_submitter(callback_id: str) -> None:
def second_submitter(callback_id: str, _context) -> None:
"""Submitter for second callback."""
print(f"Second callback submitted with ID: {callback_id}")
return None
Expand Down
8 changes: 4 additions & 4 deletions examples/src/wait_for_callback/wait_for_callback_nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import Any

from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.context import (
DurableContext,
durable_with_child_context,
)
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration


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

nested_callback_result: str = inner_child_ctx.wait_for_callback(
lambda _: None,
lambda _callback_id, _context: None,
name="nested-callback-op",
)

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

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

Expand Down
4 changes: 2 additions & 2 deletions examples/src/wait_for_callback/wait_for_callback_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from datetime import datetime
from typing import Any, Optional, TypedDict

from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.serdes import SerDes


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

result: CustomData = context.wait_for_callback(
lambda _: None,
lambda _callback_id, _context: None,
name="custom-serdes-callback",
config=config,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

from typing import Any

from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.retries import (
RetryStrategyConfig,
create_retry_strategy,
)
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig


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

def submitter(callback_id: str) -> None:
def submitter(callback_id: str, _context) -> None:
"""Submitter function that can fail based on event parameter."""
print(f"Submitting callback to external system - callbackId: {callback_id}")
raise Exception("Simulated submitter failure")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import time
from typing import Any

from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.retries import (
RetryStrategyConfig,
create_retry_strategy,
)
from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig


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

def submitter(_) -> None:
def submitter(_callback_id, _context) -> None:
"""Submitter function that fails after a delay."""
time.sleep(0.5)
# Submitter fails
Expand Down
5 changes: 2 additions & 3 deletions examples/src/wait_for_callback/wait_for_callback_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from typing import Any

from aws_durable_execution_sdk_python.config import Duration, WaitForCallbackConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.config import WaitForCallbackConfig


@durable_execution
Expand All @@ -16,7 +15,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
timeout=Duration.from_seconds(1), heartbeat_timeout=Duration.from_seconds(2)
)

def submitter(_) -> None:
def submitter(_callback_id, _context) -> None:
"""Submitter succeeds but callback never completes."""
return None

Expand Down
Loading