mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 16:28:55 +00:00
Add a timeout to the reqwest client
This commit is contained in:
parent
67a7eb9aec
commit
2be38a3759
2 changed files with 13 additions and 11 deletions
|
@ -9,7 +9,7 @@ use models::*;
|
|||
use request::builders::*;
|
||||
use request::*;
|
||||
use reqwest::Client as HTTPClient;
|
||||
use std::convert::TryInto;
|
||||
use std::{convert::TryInto, time::Duration};
|
||||
use youmubot_prelude::{ratelimit::Ratelimit, *};
|
||||
|
||||
/// 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.
|
||||
pub fn new(key: String) -> Client {
|
||||
let client = Ratelimit::new(
|
||||
HTTPClient::new(),
|
||||
HTTPClient::builder()
|
||||
.timeout(Duration::from_secs(2))
|
||||
.build()
|
||||
.expect("Client should be built"),
|
||||
REQUESTS_PER_MINUTE,
|
||||
std::time::Duration::from_secs(60),
|
||||
);
|
||||
|
|
|
@ -163,15 +163,14 @@ impl AnnouncerHandler {
|
|||
async move {
|
||||
loop {
|
||||
eprintln!(" - scanning key `{}`", key);
|
||||
Self::announce(data.clone(), cache.clone(), key, announcer)
|
||||
.map(move |v| {
|
||||
if let Err(e) = v {
|
||||
match Self::announce(data.clone(), cache.clone(), key, announcer).await {
|
||||
Err(e) => {
|
||||
eprintln!(" - key `{}`: {:?}", *key, e)
|
||||
} else {
|
||||
}
|
||||
Ok(()) => {
|
||||
eprintln!(" - key `{}`: complete", *key)
|
||||
}
|
||||
})
|
||||
.await;
|
||||
};
|
||||
looper.tick().await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue