feat: with retry helper#390
Conversation
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class WithRetryConfig: |
There was a problem hiding this comment.
WithRetryConfig<T> will let the type flow to ChildConfig[T] | None.
ChildConfig is already Generic[T].
| max_attempts=4, | ||
| initial_delay=Duration.from_seconds(2), | ||
| backoff_rate=2.0, | ||
| jitter_strategy=__import__( |
There was a problem hiding this comment.
avoid inline imports, pls.
| retry_strategy_config=RetryStrategyConfig( | ||
| max_attempts=3, | ||
| initial_delay=Duration.from_seconds(1), | ||
| jitter_strategy=__import__( |
There was a problem hiding this comment.
avoid inline imports, pls.
| child_context_config: ChildConfig | None = None, | ||
| ) -> WithRetryConfig: | ||
| """Create a WithRetryConfig with no jitter for deterministic tests.""" | ||
| from aws_durable_execution_sdk_python.config import JitterStrategy |
There was a problem hiding this comment.
avoid inline imports, pls
| config = _make_config(wrap_with_run_in_child_context=False) | ||
|
|
||
| strategy_calls: list = [] | ||
| original_create = create_retry_strategy |
|
|
||
|
|
||
| def test_success_on_first_attempt_returns_result_without_retry_strategy(): | ||
| """Function succeeds on first attempt returns result without invoking retry strategy.""" |
There was a problem hiding this comment.
name is a little misleading, since a retry strategy is configured, the test asserts it wasn't invoked
| behavior (max_attempts, initial_delay, backoff_rate, jitter, | ||
| error filtering). The same config used for step retries. | ||
| wrap_with_run_in_child_context: Whether to wrap the retry loop in | ||
| a child context for isolation. Default True. |
There was a problem hiding this comment.
could be helpful to add:
- default True: final failure rethrown as CallableRuntimeError, original on cause
- False: original error rethrown unchanged
| Returns: | ||
| The result of func on successful execution. | ||
|
|
||
| Raises: |
There was a problem hiding this comment.
Maybe also document when the wrapped child fails, ChildOperationExecutor.process wraps
non-InvocationError/SuspendExecution exceptions as CallableRuntimeError, with the original error in cause via raise … from e. When wrap_with_run_in_child_context=False, the original exception propagates unchanged.
| @@ -0,0 +1,65 @@ | |||
| """Demonstrates with_retry wrapping a wait_for_callback operation. | |||
There was a problem hiding this comment.
not registered in examples/examples-catalog.json?
| wrap_with_run_in_child_context is False. | ||
| """ | ||
|
|
||
| retry_strategy_config: RetryStrategyConfig |
There was a problem hiding this comment.
What is this instead is Callable[[Exception, int], RetryDecision] | None, so:
config = WithRetryConfig(
retry_strategy=create_retry_strategy(RetryStrategyConfig(
max_attempts=5,
initial_delay=Duration.from_seconds(2),
backoff_rate=1.0,
)),
)
This follows the same sort of pattern as StepConfig.retry_strategy
Issue #, if available: #361
Ref pr: aws/aws-durable-execution-sdk-js#505
Description
wrap_with_run_in_child_context = falseDescription of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.