forked from mirrors/relay
Increase http timeout
This commit is contained in:
parent
1a1b10a6ba
commit
7e01cbfc41
1 changed files with 10 additions and 10 deletions
|
@ -162,6 +162,14 @@ impl std::fmt::Debug for Requests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_client(user_agent: &str) -> Client {
|
||||||
|
Client::builder()
|
||||||
|
.wrap(Tracing)
|
||||||
|
.add_default_header(("User-Agent", user_agent.to_string()))
|
||||||
|
.timeout(Duration::from_secs(15))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
|
||||||
impl Requests {
|
impl Requests {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
key_id: String,
|
key_id: String,
|
||||||
|
@ -170,12 +178,7 @@ impl Requests {
|
||||||
breakers: Breakers,
|
breakers: Breakers,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Requests {
|
Requests {
|
||||||
client: Rc::new(RefCell::new(
|
client: Rc::new(RefCell::new(build_client(&user_agent))),
|
||||||
Client::builder()
|
|
||||||
.wrap(Tracing)
|
|
||||||
.add_default_header(("User-Agent", user_agent.clone()))
|
|
||||||
.finish(),
|
|
||||||
)),
|
|
||||||
consecutive_errors: Rc::new(AtomicUsize::new(0)),
|
consecutive_errors: Rc::new(AtomicUsize::new(0)),
|
||||||
error_limit: 3,
|
error_limit: 3,
|
||||||
key_id,
|
key_id,
|
||||||
|
@ -190,10 +193,7 @@ impl Requests {
|
||||||
let count = self.consecutive_errors.fetch_add(1, Ordering::Relaxed);
|
let count = self.consecutive_errors.fetch_add(1, Ordering::Relaxed);
|
||||||
if count + 1 >= self.error_limit {
|
if count + 1 >= self.error_limit {
|
||||||
tracing::warn!("{} consecutive errors, rebuilding http client", count);
|
tracing::warn!("{} consecutive errors, rebuilding http client", count);
|
||||||
*self.client.borrow_mut() = Client::builder()
|
*self.client.borrow_mut() = build_client(&self.user_agent);
|
||||||
.wrap(Tracing)
|
|
||||||
.add_default_header(("User-Agent", self.user_agent.clone()))
|
|
||||||
.finish();
|
|
||||||
self.reset_err();
|
self.reset_err();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue