chore: 支持使用 leaky-bucket 限制请求频率 (#211)
* chore: 移除之前引入的 delay * feat: 支持为 b 站请求配置频率限制
This commit is contained in:
@@ -5,12 +5,8 @@ pub mod nfo;
|
||||
pub mod status;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use rand::Rng;
|
||||
use tokio::time;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
use crate::config::Delay;
|
||||
|
||||
pub fn init_logger(log_level: &str) {
|
||||
tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::builder().parse_lossy(log_level))
|
||||
@@ -26,19 +22,3 @@ pub fn init_logger(log_level: &str) {
|
||||
pub fn id_time_key(bvid: &String, time: &DateTime<Utc>) -> String {
|
||||
format!("{}-{}", bvid, time.timestamp())
|
||||
}
|
||||
|
||||
pub(crate) async fn delay(delay: Option<&Delay>) {
|
||||
match delay {
|
||||
None => {}
|
||||
Some(Delay::Random { min, max }) => {
|
||||
let delay = {
|
||||
let mut rng = rand::thread_rng();
|
||||
rng.gen_range(*min..=*max)
|
||||
};
|
||||
time::sleep(time::Duration::from_millis(delay)).await;
|
||||
}
|
||||
Some(Delay::Fixed(delay)) => {
|
||||
time::sleep(time::Duration::from_millis(*delay)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user