Skip to content

Commit

Permalink
feat: [torrust#468] improve tracker stats importer logs
Browse files Browse the repository at this point in the history
New format using a "target" ("TrackerStats Importer") and more info like the time spent and tracker URL.

```2024-02-12T13:32:50.123422513+00:00 [Tracker Stats Importer][INFO] Importing 2 torrents statistics from tracker udp://localhost:6969 ...
2024-02-12T13:32:50.123461943+00:00 [Tracker Stats Importer][INFO] Importing torrent torrust#1 ...
2024-02-12T13:32:50.242154360+00:00 [Tracker Stats Importer][INFO] Importing torrent torrust#2 ...
2024-02-12T13:32:50.243383523+00:00 [Tracker Stats Importer][INFO] Statistics import completed in 119.92ms
```
  • Loading branch information
josecelano committed Feb 12, 2024
1 parent 61fb333 commit bc003e4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/tracker/statistics_importer.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::sync::Arc;
use std::time::Instant;

use log::{error, info};
use text_colorizer::Colorize;

use super::service::{Service, TorrentInfo, TrackerAPIError};
use crate::config::Configuration;
use crate::databases::database::{self, Database};

const LOG_TARGET: &str = "Tracker Stats Importer";

pub struct StatisticsImporter {
database: Arc<Box<dyn Database>>,
tracker_service: Arc<Service>,
Expand All @@ -30,11 +34,15 @@ impl StatisticsImporter {
///
/// Will return an error if the database query failed.
pub async fn import_all_torrents_statistics(&self) -> Result<(), database::Error> {
info!("Importing torrents statistics from tracker ...");
let torrents = self.database.get_all_torrents_compact().await?;

info!(target: LOG_TARGET, "Importing {} torrents statistics from tracker {} ...", torrents.len().to_string().yellow(), self.tracker_url.yellow());

// Start the timer before the loop
let start_time = Instant::now();

for torrent in torrents {
info!("Updating torrent {} ...", torrent.torrent_id);
info!(target: LOG_TARGET, "Importing torrent #{} ...", torrent.torrent_id.to_string().yellow());

let ret = self.import_torrent_statistics(torrent.torrent_id, &torrent.info_hash).await;

Expand All @@ -49,6 +57,10 @@ impl StatisticsImporter {
}
}

let elapsed_time = start_time.elapsed();

info!(target: LOG_TARGET, "Statistics import completed in {:.2?}", elapsed_time);

Ok(())
}

Expand Down

0 comments on commit bc003e4

Please sign in to comment.