File tree 1 file changed +7
-7
lines changed
1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -109,10 +109,11 @@ pub trait RestApiClient {
109
109
client : Client ,
110
110
request : Request ,
111
111
rate_limit_headers : RestApiRateLimitHeaders ,
112
- retries : u64 ,
112
+ retries : u8 ,
113
113
) -> impl Future < Output = Result < Response > > + Send {
114
114
async move {
115
- for i in retries..5 {
115
+ static MAX_RETRIES : u8 = 5 ;
116
+ for i in retries..MAX_RETRIES {
116
117
let result = client
117
118
. execute ( request. try_clone ( ) . ok_or ( anyhow ! (
118
119
"Failed to clone request object for recursive behavior"
@@ -168,14 +169,11 @@ pub trait RestApiClient {
168
169
}
169
170
170
171
// check if secondary rate limit is violated; backoff and try again.
171
- if i >= 4 {
172
- break ;
173
- }
174
172
if let Some ( retry_value) = response. headers ( ) . get ( & rate_limit_headers. retry )
175
173
{
176
174
if let Ok ( retry_str) = retry_value. to_str ( ) {
177
175
if let Ok ( retry) = retry_str. parse :: < u64 > ( ) {
178
- let interval = Duration :: from_secs ( retry + i . pow ( 2 ) ) ;
176
+ let interval = Duration :: from_secs ( retry + ( i as u64 ) . pow ( 2 ) ) ;
179
177
tokio:: time:: sleep ( interval) . await ;
180
178
} else {
181
179
log:: debug!(
@@ -190,7 +188,9 @@ pub trait RestApiClient {
190
188
}
191
189
return result. map_err ( Error :: from) ;
192
190
}
193
- Err ( anyhow ! ( "REST API secondary rate limit exceeded" ) )
191
+ Err ( anyhow ! (
192
+ "REST API secondary rate limit exceeded after {MAX_RETRIES} retries."
193
+ ) )
194
194
}
195
195
}
196
196
You can’t perform that action at this time.
0 commit comments