mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 16:58: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::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),
|
||||||
);
|
);
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue