File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -109,10 +109,11 @@ pub trait RestApiClient {
109109 client : Client ,
110110 request : Request ,
111111 rate_limit_headers : RestApiRateLimitHeaders ,
112- retries : u64 ,
112+ retries : u8 ,
113113 ) -> impl Future < Output = Result < Response > > + Send {
114114 async move {
115- for i in retries..5 {
115+ static MAX_RETRIES : u8 = 5 ;
116+ for i in retries..MAX_RETRIES {
116117 let result = client
117118 . execute ( request. try_clone ( ) . ok_or ( anyhow ! (
118119 "Failed to clone request object for recursive behavior"
@@ -168,14 +169,11 @@ pub trait RestApiClient {
168169 }
169170
170171 // check if secondary rate limit is violated; backoff and try again.
171- if i >= 4 {
172- break ;
173- }
174172 if let Some ( retry_value) = response. headers ( ) . get ( & rate_limit_headers. retry )
175173 {
176174 if let Ok ( retry_str) = retry_value. to_str ( ) {
177175 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 ) ) ;
179177 tokio:: time:: sleep ( interval) . await ;
180178 } else {
181179 log:: debug!(
@@ -190,7 +188,9 @@ pub trait RestApiClient {
190188 }
191189 return result. map_err ( Error :: from) ;
192190 }
193- Err ( anyhow ! ( "REST API secondary rate limit exceeded" ) )
191+ Err ( anyhow ! (
192+ "REST API secondary rate limit exceeded after {MAX_RETRIES} retries."
193+ ) )
194194 }
195195 }
196196
You can’t perform that action at this time.
0 commit comments