fix: log level issue

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-03-29 14:22:12 +01:00
parent 8a07bf163c
commit 74fe2a3b4a
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE
2 changed files with 26 additions and 6 deletions

View file

@ -3,8 +3,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-only
use std::{env, io, net::SocketAddr};
use std::time::{Duration, Instant};
use std::{env, io, net::SocketAddr};
use dns_lookup::lookup_host;
use futures::future::join_all;
@ -32,8 +32,6 @@ async fn main() -> io::Result<()> {
let host_name: String;
let cache_url: String;
pretty_env_logger::init();
let matches = cli::build_cli().get_matches();
// TODO
@ -52,6 +50,11 @@ async fn main() -> io::Result<()> {
}
}
//pretty_env_logger::init();
pretty_env_logger::formatted_timed_builder()
.parse_env("RUST_LOG")
.init();
if let Some(name) = matches.get_one::<String>("name") {
host_name = name.to_owned();
} else {
@ -80,6 +83,11 @@ async fn main() -> io::Result<()> {
let get_requisites_duration = initial_time.elapsed().as_secs();
println!(
"Found Nix Requisites in {} seconds",
get_requisites_duration
);
let network_time = Instant::now();
let lines = binding
@ -107,10 +115,17 @@ async fn main() -> io::Result<()> {
.map(|result| result.unwrap())
.sum();
println!("Found Nix Requisites in {} seconds", get_requisites_duration);
println!("Checked {count} packages in {} seconds", network_time.elapsed().as_secs());
println!(
"Checked {count} packages in {} seconds",
network_time.elapsed().as_secs()
);
println!("");
println!("Found {:#?}/{} ({:.2}%) in cache", sum, count, (sum as f64 /count as f64) * 100.);
println!(
"Found {:#?}/{} ({:.2}%) in cache",
sum,
count,
(sum as f64 / count as f64) * 100.
);
Ok(())
}

View file

@ -4,6 +4,9 @@ use async_recursion::async_recursion;
use reqwest::Client;
use tokio::time::sleep;
#[allow(unused)]
use log::{debug, error, info, trace, warn};
const MAX_SLIDE: u64 = 1000;
#[async_recursion]
@ -21,6 +24,8 @@ pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) ->
//
// Writng an actual sliding window seems kinda hard,
// so we do this instead.
trace!("rate limited! {slide}");
println!("");
sleep(Duration::from_millis(slide)).await;
nar_exists(client, domain, hash, std::cmp::min(slide * 2, MAX_SLIDE)).await
}