mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
♻️ refactor: reimplement the random delay code without the rand crate (#380)
This commit is contained in:
parent
89ee79cd0f
commit
3742893c19
@ -8,8 +8,8 @@ use crate::models::{
|
|||||||
engine_models::{EngineError, EngineHandler},
|
engine_models::{EngineError, EngineHandler},
|
||||||
};
|
};
|
||||||
use error_stack::Report;
|
use error_stack::Report;
|
||||||
use rand::Rng;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{BufReader, Read},
|
io::{BufReader, Read},
|
||||||
@ -72,9 +72,9 @@ pub async fn aggregate(
|
|||||||
|
|
||||||
// Add a random delay before making the request.
|
// Add a random delay before making the request.
|
||||||
if random_delay || !debug {
|
if random_delay || !debug {
|
||||||
let mut rng = rand::thread_rng();
|
let nanos = SystemTime::now().duration_since(UNIX_EPOCH)?.subsec_nanos() as f32;
|
||||||
let delay_secs = rng.gen_range(1..10);
|
let delay = ((nanos / 1_0000_0000 as f32).floor() as u64) + 1;
|
||||||
tokio::time::sleep(Duration::from_secs(delay_secs)).await;
|
tokio::time::sleep(Duration::from_secs(delay)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut names: Vec<&str> = Vec::with_capacity(0);
|
let mut names: Vec<&str> = Vec::with_capacity(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user