From 08ebf4c67458d7132aa8241ce71fcf9b4f031772 Mon Sep 17 00:00:00 2001 From: Quinn Sinclair Date: Sat, 8 Nov 2025 22:42:56 +0000 Subject: [PATCH 1/2] Update Duration API to use from_seconds() builder method - Change Duration.seconds(5) to Duration.from_seconds(5) - Aligns with Duration refactoring in main SDK --- tests/e2e/basic_success_path_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/basic_success_path_test.py b/tests/e2e/basic_success_path_test.py index a24d516..bf17002 100644 --- a/tests/e2e/basic_success_path_test.py +++ b/tests/e2e/basic_success_path_test.py @@ -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, @@ -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) From 0ada51cf5916d2c9217c2d61d114f0c6699bcbab Mon Sep 17 00:00:00 2001 From: Quinn Sinclair Date: Sat, 8 Nov 2025 22:48:53 +0000 Subject: [PATCH 2/2] Update all examples to use Duration API - Replace context.wait(seconds=N) with context.wait(Duration.from_seconds(N)) - Replace CallbackConfig(timeout_seconds=N) with CallbackConfig(timeout=Duration.from_seconds(N)) - Replace WaitForCallbackConfig timeout_seconds/heartbeat_timeout_seconds with Duration objects - Replace RetryStrategyConfig initial_delay_seconds/max_delay_seconds with Duration objects - Add Duration import to all affected files - Aligns with Duration refactoring in main SDK --- examples/src/block_example/block_example.py | 3 ++- examples/src/callback/callback.py | 6 ++++-- examples/src/callback/callback_with_timeout.py | 6 ++++-- examples/src/parallel/parallel.py | 4 ++-- examples/src/parallel/parallel_with_wait.py | 7 ++++--- .../run_in_child_context_large_data.py | 3 ++- examples/src/step/step_with_exponential_backoff.py | 7 +++++-- examples/src/step/steps_with_retry.py | 4 ++-- examples/src/wait/multiple_wait.py | 5 +++-- examples/src/wait/wait.py | 3 ++- examples/src/wait/wait_with_name.py | 3 ++- examples/src/wait_for_callback/wait_for_callback.py | 6 ++++-- examples/src/wait_for_condition/wait_for_condition.py | 3 ++- 13 files changed, 38 insertions(+), 22 deletions(-) diff --git a/examples/src/block_example/block_example.py b/examples/src/block_example/block_example.py index cb3dc72..1bf10d0 100644 --- a/examples/src/block_example/block_example.py +++ b/examples/src/block_example/block_example.py @@ -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, @@ -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" diff --git a/examples/src/callback/callback.py b/examples/src/callback/callback.py index 0c0f13b..387fe0a 100644 --- a/examples/src/callback/callback.py +++ b/examples/src/callback/callback.py @@ -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 @@ -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 diff --git a/examples/src/callback/callback_with_timeout.py b/examples/src/callback/callback_with_timeout.py index 4053e57..1acf8ca 100644 --- a/examples/src/callback/callback_with_timeout.py +++ b/examples/src/callback/callback_with_timeout.py @@ -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 @@ -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 diff --git a/examples/src/parallel/parallel.py b/examples/src/parallel/parallel.py index 205f52d..869e24b 100644 --- a/examples/src/parallel/parallel.py +++ b/examples/src/parallel/parallel.py @@ -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 @@ -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], ], diff --git a/examples/src/parallel/parallel_with_wait.py b/examples/src/parallel/parallel_with_wait.py index 746a0b0..8a2eedc 100644 --- a/examples/src/parallel/parallel_with_wait.py +++ b/examples/src/parallel/parallel_with_wait.py @@ -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 @@ -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() diff --git a/examples/src/run_in_child_context/run_in_child_context_large_data.py b/examples/src/run_in_child_context/run_in_child_context_large_data.py index cabb66e..b404481 100644 --- a/examples/src/run_in_child_context/run_in_child_context_large_data.py +++ b/examples/src/run_in_child_context/run_in_child_context_large_data.py @@ -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, @@ -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 = ( diff --git a/examples/src/step/step_with_exponential_backoff.py b/examples/src/step/step_with_exponential_backoff.py index 10ef0be..b44b388 100644 --- a/examples/src/step/step_with_exponential_backoff.py +++ b/examples/src/step/step_with_exponential_backoff.py @@ -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 ( @@ -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)) diff --git a/examples/src/step/steps_with_retry.py b/examples/src/step/steps_with_retry.py index 6d16e49..b1184b9 100644 --- a/examples/src/step/steps_with_retry.py +++ b/examples/src/step/steps_with_retry.py @@ -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 ( @@ -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 diff --git a/examples/src/wait/multiple_wait.py b/examples/src/wait/multiple_wait.py index 7a13402..880881f 100644 --- a/examples/src/wait/multiple_wait.py +++ b/examples/src/wait/multiple_wait.py @@ -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 @@ -9,8 +10,8 @@ @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, diff --git a/examples/src/wait/wait.py b/examples/src/wait/wait.py index f91c47d..1ef2393 100644 --- a/examples/src/wait/wait.py +++ b/examples/src/wait/wait.py @@ -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" diff --git a/examples/src/wait/wait_with_name.py b/examples/src/wait/wait_with_name.py index 11ac992..8d0ec27 100644 --- a/examples/src/wait/wait_with_name.py +++ b/examples/src/wait/wait_with_name.py @@ -1,5 +1,6 @@ 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 @@ -7,5 +8,5 @@ @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" diff --git a/examples/src/wait_for_callback/wait_for_callback.py b/examples/src/wait_for_callback/wait_for_callback.py index 0f72c19..3ff915a 100644 --- a/examples/src/wait_for_callback/wait_for_callback.py +++ b/examples/src/wait_for_callback/wait_for_callback.py @@ -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 @@ -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 diff --git a/examples/src/wait_for_condition/wait_for_condition.py b/examples/src/wait_for_condition/wait_for_condition.py index ab9d434..80fb231 100644 --- a/examples/src/wait_for_condition/wait_for_condition.py +++ b/examples/src/wait_for_condition/wait_for_condition.py @@ -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 @@ -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