Skip to content

Commit

Permalink
refactor: [torrust#453] reorganize console mods
Browse files Browse the repository at this point in the history
```console
src/console/
├── commands
│   ├── mod.rs
│   └── tracker_statistics_importer
│       ├── app.rs
│       └── mod.rs
├── cronjobs
│   ├── mod.rs
│   └── tracker_statistics_importer.rs
└── mod.rs
```

- We will create a new command to seed the Index with random torrents.
- This new strcuture is similar to what we have in the Tracker.
  • Loading branch information
josecelano committed Feb 6, 2024
1 parent 17f2364 commit b1df4e8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running

// Start cronjob to import tracker torrent data and updating
// seeders and leechers info.
let tracker_statistics_importer_handle = console::tracker_statistics_importer::start(
let tracker_statistics_importer_handle = console::cronjobs::tracker_statistics_importer::start(
importer_port,
importer_torrent_info_update_interval,
&tracker_statistics_importer,
Expand Down
6 changes: 3 additions & 3 deletions src/bin/import_tracker_statistics.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Import Tracker Statistics command.
//!
//! It imports the number of seeders and leechers for all torrent from the linked tracker.
//! It imports the number of seeders and leechers for all torrents from the linked tracker.
//!
//! You can execute it with: `cargo run --bin import_tracker_statistics`
use torrust_index::console::commands::import_tracker_statistics::run_importer;
use torrust_index::console::commands::tracker_statistics_importer::app::run;

#[tokio::main]
async fn main() {
run_importer().await;
run().await;
}
2 changes: 1 addition & 1 deletion src/console/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod import_tracker_statistics;
pub mod tracker_statistics_importer;
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn print_usage() {
/// # Panics
///
/// Panics if arguments cannot be parsed.
pub async fn run_importer() {
pub async fn run() {
parse_args().expect("unable to parse command arguments");
import().await;
}
Expand Down
1 change: 1 addition & 0 deletions src/console/commands/tracker_statistics_importer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod app;
1 change: 1 addition & 0 deletions src/console/cronjobs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod tracker_statistics_importer;
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ struct ImporterState {
pub torrent_info_update_interval: u64,
}

/// # Panics
///
/// Will panic if it can't start the tracker statistics importer API
#[must_use]
pub fn start(
importer_port: u16,
torrent_info_update_interval: u64,
Expand Down Expand Up @@ -60,7 +64,7 @@ pub fn start(

let addr = format!("{IMPORTER_API_IP}:{importer_port}");

info!("Tracker statistics importer API server listening on http://{}", addr);
info!("Tracker statistics importer API server listening on http://{}", addr); // # DevSkim: ignore DS137138

axum::Server::bind(&addr.parse().unwrap())
.serve(app.into_make_service())
Expand Down Expand Up @@ -122,7 +126,7 @@ async fn heartbeat_handler(State(state): State<Arc<ImporterState>>) -> Json<Valu
/// Send a heartbeat from the importer cronjob to the importer API.
async fn send_heartbeat(importer_port: u16) -> Result<(), reqwest::Error> {
let client = reqwest::Client::new();
let url = format!("http://{IMPORTER_API_IP}:{importer_port}/heartbeat");
let url = format!("http://{IMPORTER_API_IP}:{importer_port}/heartbeat"); // # DevSkim: ignore DS137138

client.post(url).send().await?;

Expand Down
2 changes: 1 addition & 1 deletion src/console/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod commands;
pub(crate) mod tracker_statistics_importer;
pub mod cronjobs;

0 comments on commit b1df4e8

Please sign in to comment.