55from enum import StrEnum
66import random
77import re
8- import sys
98from dataclasses import dataclass , field
109from typing import TYPE_CHECKING
10+ import math
1111
1212if TYPE_CHECKING :
1313 from collections .abc import Callable
@@ -66,7 +66,7 @@ def no_retry(cls) -> RetryDecision:
6666
6767@dataclass
6868class RetryStrategyConfig :
69- max_attempts : int = sys . maxsize # "infinite", practically
69+ max_attempts : int = 3 # "infinite", practically
7070 initial_delay_seconds : int = 5
7171 max_delay_seconds : int = 300 # 5 minutes
7272 backoff_rate : Numeric = 2.0
@@ -109,8 +109,9 @@ def retry_strategy(error: Exception, attempts_made: int) -> RetryDecision:
109109 config .initial_delay_seconds * (config .backoff_rate ** (attempts_made - 1 )),
110110 config .max_delay_seconds ,
111111 )
112- jitter = config .jitter_strategy .compute_jitter (delay )
113- final_delay = max (1 , delay + jitter )
112+ delay_with_jitter = delay + config .jitter_strategy .compute_jitter (delay )
113+ delay_with_jitter = math .ceil (delay_with_jitter )
114+ final_delay = max (1 , delay_with_jitter )
114115
115116 return RetryDecision .retry (round (final_delay ))
116117
@@ -123,17 +124,18 @@ class RetryPresets:
123124 @classmethod
124125 def none (cls ) -> Callable [[Exception , int ], RetryDecision ]:
125126 """No retries."""
126- return create_retry_strategy (RetryStrategyConfig (max_attempts = 0 ))
127+ return create_retry_strategy (RetryStrategyConfig (max_attempts = 1 ))
127128
128129 @classmethod
129130 def default (cls ) -> Callable [[Exception , int ], RetryDecision ]:
130131 """Default retries, will be used automatically if retryConfig is missing"""
131132 return create_retry_strategy (
132133 RetryStrategyConfig (
133- max_attempts = sys . maxsize ,
134+ max_attempts = 6 ,
134135 initial_delay_seconds = 5 ,
135136 max_delay_seconds = 60 ,
136137 backoff_rate = 2 ,
138+ jitter_strategy = JitterStrategy .FULL
137139 )
138140 )
139141
0 commit comments