Add a timeout to the reqwest client

This commit is contained in:
Natsu Kagami 2023-11-21 13:27:22 +01:00
parent 67a7eb9aec
commit 2be38a3759
Signed by: nki
GPG key ID: 55A032EB38B49ADB
2 changed files with 13 additions and 11 deletions

View file

@ -9,7 +9,7 @@ use models::*;
use request::builders::*; use request::builders::*;
use request::*; use request::*;
use reqwest::Client as HTTPClient; use reqwest::Client as HTTPClient;
use std::convert::TryInto; use std::{convert::TryInto, time::Duration};
use youmubot_prelude::{ratelimit::Ratelimit, *}; use youmubot_prelude::{ratelimit::Ratelimit, *};
/// The number of requests per minute to the osu! server. /// The number of requests per minute to the osu! server.
@ -35,7 +35,10 @@ impl Client {
/// Create a new client from the given API key. /// Create a new client from the given API key.
pub fn new(key: String) -> Client { pub fn new(key: String) -> Client {
let client = Ratelimit::new( let client = Ratelimit::new(
HTTPClient::new(), HTTPClient::builder()
.timeout(Duration::from_secs(2))
.build()
.expect("Client should be built"),
REQUESTS_PER_MINUTE, REQUESTS_PER_MINUTE,
std::time::Duration::from_secs(60), std::time::Duration::from_secs(60),
); );

View file

@ -163,15 +163,14 @@ impl AnnouncerHandler {
async move { async move {
loop { loop {
eprintln!(" - scanning key `{}`", key); eprintln!(" - scanning key `{}`", key);
Self::announce(data.clone(), cache.clone(), key, announcer) match Self::announce(data.clone(), cache.clone(), key, announcer).await {
.map(move |v| { Err(e) => {
if let Err(e) = v {
eprintln!(" - key `{}`: {:?}", *key, e) eprintln!(" - key `{}`: {:?}", *key, e)
} else { }
Ok(()) => {
eprintln!(" - key `{}`: complete", *key) eprintln!(" - key `{}`: complete", *key)
} }
}) };
.await;
looper.tick().await; looper.tick().await;
} }
} }