1
+ use std:: time:: Duration ;
2
+
1
3
use crate :: agent:: Capabilities ;
2
4
use crate :: crates:: Crate ;
3
5
use crate :: experiments:: Experiment ;
@@ -62,8 +64,6 @@ impl ResponseExt for ::reqwest::blocking::Response {
62
64
}
63
65
}
64
66
65
- const RETRY_AFTER : u64 = 5 ;
66
-
67
67
pub struct AgentApi {
68
68
url : String ,
69
69
token : String ,
@@ -88,6 +88,7 @@ impl AgentApi {
88
88
}
89
89
90
90
fn retry < T , F : Fn ( & Self ) -> Fallible < T > > ( & self , f : F ) -> Fallible < T > {
91
+ let mut retry_interval = 16u64 ;
91
92
loop {
92
93
match f ( self ) {
93
94
Ok ( res) => return Ok ( res) ,
@@ -104,10 +105,19 @@ impl AgentApi {
104
105
} ;
105
106
106
107
if retry {
107
- warn ! ( "connection to the server failed. retrying in a few seconds..." ) ;
108
- :: std:: thread:: sleep ( :: std:: time:: Duration :: from_millis (
109
- rand:: thread_rng ( ) . gen_range ( 0 ..( RETRY_AFTER * 1000 ) ) ,
110
- ) ) ;
108
+ let sleep_for = Duration :: from_millis (
109
+ rand:: thread_rng ( ) . gen_range ( 500 ..( retry_interval * 1000 ) ) ,
110
+ ) ;
111
+ warn ! (
112
+ "connection to the server failed. retrying in {:?}..." ,
113
+ sleep_for
114
+ ) ;
115
+ :: std:: thread:: sleep ( sleep_for) ;
116
+ retry_interval *= 2 ;
117
+ if retry_interval >= 8 * 60 {
118
+ retry_interval = 8 * 60 ;
119
+ }
120
+
111
121
continue ;
112
122
}
113
123
@@ -141,7 +151,7 @@ impl AgentApi {
141
151
// healthy.
142
152
crate :: agent:: set_healthy ( ) ;
143
153
144
- :: std:: thread:: sleep ( :: std :: time :: Duration :: from_secs ( 120 ) ) ;
154
+ :: std:: thread:: sleep ( Duration :: from_secs ( 120 ) ) ;
145
155
} )
146
156
}
147
157
0 commit comments