|
1 | | -# Retries |
| 1 | +# Retry strategies |
2 | 2 |
|
3 | | -## Table of Contents |
| 3 | +Retry strategies configure how the SDK responds to failures in steps. You control the |
| 4 | +number of attempts, delay between retries, backoff rate, and which exceptions trigger a |
| 5 | +retry. If no retry strategy is configured on a step, any exception propagates |
| 6 | +immediately and fails the execution. |
4 | 7 |
|
5 | | -- [Overview](#overview) |
6 | | -- [Creating retry strategies](#creating-retry-strategies) |
7 | | -- [RetryStrategyConfig parameters](#retrystrategyconfig-parameters) |
8 | | -- [Retry presets](#retry-presets) |
9 | | -- [Retrying specific exceptions](#retrying-specific-exceptions) |
10 | | -- [Exponential backoff](#exponential-backoff) |
| 8 | +## Creating a retry strategy |
11 | 9 |
|
12 | | -[← Back to main index](../index.md) |
13 | | - |
14 | | -## Overview |
15 | | - |
16 | | -Retry strategies configure how the SDK responds to transient failures in steps. You can control the number of attempts, delay between retries, backoff rate, and which exceptions trigger a retry. |
17 | | - |
18 | | -[↑ Back to top](#table-of-contents) |
19 | | - |
20 | | -## Creating retry strategies |
21 | | - |
22 | | -Use `RetryStrategyConfig` to define retry behavior: |
| 10 | +Use `createRetryStrategy()` (TypeScript/Python) or |
| 11 | +`RetryStrategies.exponentialBackoff()` (Java) to build a strategy, then pass it to |
| 12 | +`StepConfig`: |
23 | 13 |
|
24 | 14 | === "TypeScript" |
25 | 15 |
|
26 | | - ``` typescript |
27 | | - --8<-- "examples/typescript/core/steps/unreliable-operation.ts" |
| 16 | + ```typescript |
| 17 | + --8<-- "examples/typescript/advanced/error-handling/exponential-backoff.ts" |
28 | 18 | ``` |
29 | 19 |
|
30 | 20 | === "Python" |
31 | 21 |
|
32 | | - ``` python |
33 | | - --8<-- "examples/python/core/steps/unreliable-operation.py" |
| 22 | + ```python |
| 23 | + --8<-- "examples/python/advanced/error-handling/exponential-backoff.py" |
34 | 24 | ``` |
35 | 25 |
|
36 | 26 | === "Java" |
37 | 27 |
|
38 | | - ``` java |
39 | | - --8<-- "examples/java/core/steps/unreliable-operation.java" |
| 28 | + ```java |
| 29 | + --8<-- "examples/java/advanced/error-handling/exponential-backoff.java" |
40 | 30 | ``` |
41 | 31 |
|
42 | | -[↑ Back to top](#table-of-contents) |
43 | | - |
44 | 32 | ## RetryStrategyConfig parameters |
45 | 33 |
|
46 | | -**max_attempts** - Maximum number of attempts (including the initial attempt). Default: 3. |
| 34 | +**max_attempts / maxAttempts** Maximum number of attempts including the initial attempt. |
| 35 | +Default: 3. |
47 | 36 |
|
48 | | -**initial_delay_seconds** - Initial delay before first retry in seconds. Default: 5. |
| 37 | +**initial_delay / initialDelay** Delay before the first retry. Default: 5 seconds. |
49 | 38 |
|
50 | | -**max_delay_seconds** - Maximum delay between retries in seconds. Default: 300 (5 minutes). |
| 39 | +**max_delay / maxDelay** Maximum delay between retries. Default: 5 minutes. |
51 | 40 |
|
52 | | -**backoff_rate** - Multiplier for exponential backoff. Default: 2.0. |
| 41 | +**backoff_rate / backoffRate** Multiplier for exponential backoff. Default: 2.0. |
53 | 42 |
|
54 | | -**jitter_strategy** - Jitter strategy to add randomness to delays. Default: `JitterStrategy.FULL`. |
| 43 | +**jitter_strategy / jitter** Jitter strategy to spread retries. Default: `FULL`. |
55 | 44 |
|
56 | | -**retryable_errors** - List of error message patterns to retry (strings or regex patterns). Default: matches all errors. |
| 45 | +**retryable_errors / retryableErrors** Error message patterns to retry (strings or |
| 46 | +regex). Default: matches all errors. |
57 | 47 |
|
58 | | -**retryable_error_types** - List of exception types to retry. Default: empty (retry all). |
59 | | - |
60 | | -[↑ Back to top](#table-of-contents) |
| 48 | +**retryable_error_types / retryableErrorTypes** Exception types to retry. Default: empty |
| 49 | +(retries all). |
61 | 50 |
|
62 | 51 | ## Retry presets |
63 | 52 |
|
64 | | -The SDK provides preset retry strategies for common scenarios: |
65 | | - |
66 | 53 | === "TypeScript" |
67 | 54 |
|
68 | | - ``` typescript |
| 55 | + ```typescript |
69 | 56 | --8<-- "examples/typescript/advanced/error-handling/retry-presets.ts" |
70 | 57 | ``` |
71 | 58 |
|
72 | 59 | === "Python" |
73 | 60 |
|
74 | | - ``` python |
| 61 | + ```python |
75 | 62 | --8<-- "examples/python/advanced/error-handling/retry-presets.py" |
76 | 63 | ``` |
77 | 64 |
|
78 | 65 | === "Java" |
79 | 66 |
|
80 | | - ``` java |
| 67 | + ```java |
81 | 68 | --8<-- "examples/java/advanced/error-handling/retry-presets.java" |
82 | 69 | ``` |
83 | 70 |
|
84 | | -[↑ Back to top](#table-of-contents) |
85 | | - |
86 | 71 | ## Retrying specific exceptions |
87 | 72 |
|
88 | | -Only retry certain exception types: |
89 | | - |
90 | 73 | === "TypeScript" |
91 | 74 |
|
92 | | - ``` typescript |
93 | | - --8<-- "examples/typescript/advanced/error-handling/retry-specific-exceptions.ts" |
| 75 | + ```typescript |
| 76 | + --8<-- "examples/typescript/sdk-reference/error-handling/unreliable-operation.ts" |
94 | 77 | ``` |
95 | 78 |
|
96 | 79 | === "Python" |
97 | 80 |
|
98 | | - ``` python |
99 | | - --8<-- "examples/python/advanced/error-handling/retry-specific-exceptions.py" |
| 81 | + ```python |
| 82 | + --8<-- "examples/python/sdk-reference/error-handling/unreliable-operation.py" |
100 | 83 | ``` |
101 | 84 |
|
102 | 85 | === "Java" |
103 | 86 |
|
104 | | - ``` java |
105 | | - --8<-- "examples/java/advanced/error-handling/retry-specific-exceptions.java" |
| 87 | + ```java |
| 88 | + --8<-- "examples/java/sdk-reference/error-handling/unreliable-operation.java" |
106 | 89 | ``` |
107 | 90 |
|
108 | | -[↑ Back to top](#table-of-contents) |
109 | | - |
110 | | -## Exponential backoff |
111 | | - |
112 | | -Configure exponential backoff to avoid overwhelming failing services: |
113 | | - |
114 | | -=== "TypeScript" |
115 | | - |
116 | | - ``` typescript |
117 | | - --8<-- "examples/typescript/advanced/error-handling/exponential-backoff.ts" |
118 | | - ``` |
119 | | - |
120 | | -=== "Python" |
121 | | - |
122 | | - ``` python |
123 | | - --8<-- "examples/python/advanced/error-handling/exponential-backoff.py" |
124 | | - ``` |
125 | | - |
126 | | -=== "Java" |
127 | | - |
128 | | - ``` java |
129 | | - --8<-- "examples/java/advanced/error-handling/exponential-backoff.java" |
130 | | - ``` |
131 | | - |
132 | | -With this configuration: |
133 | | -- Attempt 1: Immediate |
134 | | -- Attempt 2: After 1 second |
135 | | -- Attempt 3: After 2 seconds |
136 | | -- Attempt 4: After 4 seconds |
137 | | -- Attempt 5: After 8 seconds |
138 | | - |
139 | | -[↑ Back to top](#table-of-contents) |
140 | | - |
141 | 91 | ## See also |
142 | 92 |
|
143 | | -- [Errors](errors.md) - Exception types and error responses |
144 | | -- [Step](../operations/step.md) - Configure retry for steps |
| 93 | +- [Errors](errors.md) |
| 94 | +- [Steps](../operations/step.md) |
0 commit comments