Skip to content
Closed
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
3 changes: 2 additions & 1 deletion examples/src/block_example/block_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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,
Expand All @@ -13,7 +14,7 @@
def nested_block(ctx: DurableContext) -> str:
"""Nested block with its own child context."""
# Wait in the nested block
ctx.wait(seconds=1)
ctx.wait(Duration.from_seconds(1))
return "nested block result"


Expand Down
6 changes: 4 additions & 2 deletions examples/src/callback/callback.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any

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

Expand All @@ -11,7 +11,9 @@

@durable_execution
def handler(_event: Any, context: DurableContext) -> str:
callback_config = CallbackConfig(timeout_seconds=120, heartbeat_timeout_seconds=60)
callback_config = CallbackConfig(
timeout=Duration.from_minutes(2), heartbeat_timeout=Duration.from_minutes(1)
)

callback: Callback[str] = context.create_callback(
name="example_callback", config=callback_config
Expand Down
6 changes: 4 additions & 2 deletions examples/src/callback/callback_with_timeout.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING, Any

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

Expand All @@ -12,7 +12,9 @@
@durable_execution
def handler(_event: Any, context: DurableContext) -> str:
# Callback with custom timeout configuration
config = CallbackConfig(timeout_seconds=60, heartbeat_timeout_seconds=30)
config = CallbackConfig(
timeout=Duration.from_minutes(1), heartbeat_timeout=Duration.from_seconds(30)
)

callback: Callback[str] = context.create_callback(
name="timeout_callback", config=config
Expand Down
4 changes: 2 additions & 2 deletions examples/src/parallel/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any

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

Expand All @@ -17,7 +17,7 @@ def handler(_event: Any, context: DurableContext) -> list[str]:
lambda ctx: ctx.step(lambda _: "task 1 completed", name="task1"),
lambda ctx: ctx.step(lambda _: "task 2 completed", name="task2"),
lambda ctx: (
ctx.wait(1, name="wait_in_task3"),
ctx.wait(Duration.from_seconds(1), name="wait_in_task3"),
"task 3 completed after wait",
)[1],
],
Expand Down
7 changes: 4 additions & 3 deletions examples/src/parallel/parallel_with_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand All @@ -13,9 +14,9 @@ def handler(_event: Any, context: DurableContext) -> str:
# Call get_results() to extract data and avoid BatchResult serialization
context.parallel(
functions=[
lambda ctx: ctx.wait(1, name="wait_1_second"),
lambda ctx: ctx.wait(2, name="wait_2_seconds"),
lambda ctx: ctx.wait(5, name="wait_5_seconds"),
lambda ctx: ctx.wait(Duration.from_seconds(1), name="wait_1_second"),
lambda ctx: ctx.wait(Duration.from_seconds(2), name="wait_2_seconds"),
lambda ctx: ctx.wait(Duration.from_seconds(5), name="wait_5_seconds"),
],
name="parallel_waits",
).get_results()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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,
Expand Down Expand Up @@ -55,7 +56,7 @@ def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
)

# Add a wait after runInChildContext to test persistence across invocations
context.wait(seconds=1, name="post-processing-wait")
context.wait(Duration.from_seconds(1), name="post-processing-wait")

# Verify the data is still intact after the wait
data_integrity_check = (
Expand Down
7 changes: 5 additions & 2 deletions examples/src/step/step_with_exponential_backoff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from aws_durable_execution_sdk_python.config import StepConfig
from aws_durable_execution_sdk_python.config import Duration, StepConfig
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 (
Expand All @@ -13,7 +13,10 @@
def handler(_event: Any, context: DurableContext) -> str:
# Step with exponential backoff retry strategy
retry_config = RetryStrategyConfig(
max_attempts=3, initial_delay_seconds=1, max_delay_seconds=10, backoff_rate=2.0
max_attempts=3,
initial_delay=Duration.from_seconds(1),
max_delay=Duration.from_seconds(10),
backoff_rate=2.0,
)

step_config = StepConfig(retry_strategy=create_retry_strategy(retry_config))
Expand Down
4 changes: 2 additions & 2 deletions examples/src/step/steps_with_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from random import random
from typing import Any

from aws_durable_execution_sdk_python.config import StepConfig
from aws_durable_execution_sdk_python.config import Duration, StepConfig
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 (
Expand Down Expand Up @@ -60,7 +60,7 @@ def handler(event: Any, context: DurableContext) -> dict[str, Any]:
break

# Wait 1 second until next poll
context.wait(seconds=1)
context.wait(Duration.from_seconds(1))

except RuntimeError as e:
# Retries exhausted
Expand Down
5 changes: 3 additions & 2 deletions examples/src/wait/multiple_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

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


@durable_execution
def handler(_event: Any, context: DurableContext) -> dict[str, Any]:
"""Handler demonstrating multiple sequential wait operations."""
context.wait(seconds=5, name="wait-1")
context.wait(seconds=5, name="wait-2")
context.wait(Duration.from_seconds(5), name="wait-1")
context.wait(Duration.from_seconds(5), name="wait-2")

return {
"completedWaits": 2,
Expand Down
3 changes: 2 additions & 1 deletion examples/src/wait/wait.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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


@durable_execution
def handler(_event: Any, context: DurableContext) -> str:
context.wait(seconds=5)
context.wait(Duration.from_seconds(5))
return "Wait completed"
3 changes: 2 additions & 1 deletion examples/src/wait/wait_with_name.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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


@durable_execution
def handler(_event: Any, context: DurableContext) -> str:
# Wait with explicit name
context.wait(seconds=2, name="custom_wait")
context.wait(Duration.from_seconds(2), name="custom_wait")
return "Wait with name completed"
6 changes: 4 additions & 2 deletions examples/src/wait_for_callback/wait_for_callback.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from aws_durable_execution_sdk_python.config import WaitForCallbackConfig
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

Expand All @@ -13,7 +13,9 @@ def external_system_call(_callback_id: str) -> None:

@durable_execution
def handler(_event: Any, context: DurableContext) -> str:
config = WaitForCallbackConfig(timeout_seconds=120, heartbeat_timeout_seconds=60)
config = WaitForCallbackConfig(
timeout=Duration.from_minutes(2), heartbeat_timeout=Duration.from_minutes(1)
)

result = context.wait_for_callback(
external_system_call, name="external_call", config=config
Expand Down
3 changes: 2 additions & 1 deletion examples/src/wait_for_condition/wait_for_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand All @@ -28,6 +29,6 @@ def handler(_event: Any, context: DurableContext) -> int:
break

# Wait before next attempt
context.wait(seconds=1)
context.wait(Duration.from_seconds(1))

return state
3 changes: 2 additions & 1 deletion tests/e2e/basic_success_path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from typing import Any

from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.context import (
DurableContext,
durable_step,
Expand Down Expand Up @@ -58,7 +59,7 @@ def function_under_test(event: Any, context: DurableContext) -> list[str]:
result_one: str = context.step(one(1, 2))
results.append(result_one)

context.wait(seconds=1)
context.wait(duration=Duration.from_seconds(5))

result_two: str = context.run_in_child_context(two(3, 4))
results.append(result_two)
Expand Down
Loading