Skip to content

Commit

Permalink
feat!: [#143] move config option torrent_info_update_interval
Browse files Browse the repository at this point in the history
from database section to a new section:

```
[tracker_statistics_importer]
torrent_info_update_interval = 3600
```
  • Loading branch information
josecelano committed May 16, 2023
1 parent 4cde9ec commit 57642ea
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config-idx-back.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ secret_key = "MaxVerstappenWC2021"
[database]
connect_url = "sqlite://storage/database/torrust_index_backend_e2e_testing.db?mode=rwc" # SQLite
#connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index_backend" # MySQL
torrent_info_update_interval = 3600

[mail]
email_verification_enabled = false
Expand All @@ -42,3 +41,5 @@ user_quota_bytes = 64000000
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
torrent_info_update_interval = 3600
4 changes: 3 additions & 1 deletion config.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ secret_key = "MaxVerstappenWC2021"

[database]
connect_url = "sqlite://data.db?mode=rwc"
torrent_info_update_interval = 3600

[mail]
email_verification_enabled = false
Expand All @@ -40,3 +39,6 @@ user_quota_bytes = 64000000
[api]
default_torrent_page_size = 10
max_torrent_page_size = 30

[tracker_statistics_importer]
torrent_info_update_interval = 3600
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn run(configuration: Configuration) -> Running {
let settings = cfg.settings.read().await;

let database_connect_url = settings.database.connect_url.clone();
let database_torrent_info_update_interval = settings.database.torrent_info_update_interval;
let torrent_info_update_interval = settings.tracker_statistics_importer.torrent_info_update_interval;
let net_port = settings.net.port;

// IMPORTANT: drop settings before starting server to avoid read locks that
Expand Down Expand Up @@ -67,7 +67,7 @@ pub async fn run(configuration: Configuration) -> Running {
let weak_tracker_statistics_importer = Arc::downgrade(&tracker_statistics_importer);

let tracker_statistics_importer_handle = tokio::spawn(async move {
let interval = std::time::Duration::from_secs(database_torrent_info_update_interval);
let interval = std::time::Duration::from_secs(torrent_info_update_interval);
let mut interval = tokio::time::interval(interval);
interval.tick().await; // first tick is immediate...
loop {
Expand Down
16 changes: 14 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ impl Default for Auth {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Database {
pub connect_url: String,
pub torrent_info_update_interval: u64,
}

impl Default for Database {
fn default() -> Self {
Self {
connect_url: "sqlite://data.db?mode=rwc".to_string(),
torrent_info_update_interval: 3600,
}
}
}
Expand Down Expand Up @@ -170,6 +168,19 @@ impl Default for Api {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrackerStatisticsImporter {
pub torrent_info_update_interval: u64,
}

impl Default for TrackerStatisticsImporter {
fn default() -> Self {
Self {
torrent_info_update_interval: 3600,
}
}
}

impl Default for ImageCache {
fn default() -> Self {
Self {
Expand All @@ -192,6 +203,7 @@ pub struct TorrustBackend {
pub mail: Mail,
pub image_cache: ImageCache,
pub api: Api,
pub tracker_statistics_importer: TrackerStatisticsImporter,
}

#[derive(Debug)]
Expand Down
20 changes: 17 additions & 3 deletions tests/common/contexts/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pub mod responses;
use serde::{Deserialize, Serialize};
use torrust_index_backend::config::{
Api as DomainApi, Auth as DomainAuth, Database as DomainDatabase, ImageCache as DomainImageCache, Mail as DomainMail,
Network as DomainNetwork, TorrustBackend as DomainSettings, Tracker as DomainTracker, Website as DomainWebsite,
Network as DomainNetwork, TorrustBackend as DomainSettings, Tracker as DomainTracker,
TrackerStatisticsImporter as DomainTrackerStatisticsImporter, Website as DomainWebsite,
};

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
Expand All @@ -17,6 +18,7 @@ pub struct Settings {
pub mail: Mail,
pub image_cache: ImageCache,
pub api: Api,
pub tracker_statistics_importer: TrackerStatisticsImporter,
}

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -50,7 +52,6 @@ pub struct Auth {
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
pub struct Database {
pub connect_url: String,
pub torrent_info_update_interval: u64,
}

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -79,6 +80,11 @@ pub struct Api {
pub max_torrent_page_size: u8,
}

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
pub struct TrackerStatisticsImporter {
pub torrent_info_update_interval: u64,
}

impl From<DomainSettings> for Settings {
fn from(settings: DomainSettings) -> Self {
Settings {
Expand All @@ -90,6 +96,7 @@ impl From<DomainSettings> for Settings {
mail: Mail::from(settings.mail),
image_cache: ImageCache::from(settings.image_cache),
api: Api::from(settings.api),
tracker_statistics_importer: TrackerStatisticsImporter::from(settings.tracker_statistics_importer),
}
}
}
Expand Down Expand Up @@ -136,7 +143,6 @@ impl From<DomainDatabase> for Database {
fn from(database: DomainDatabase) -> Self {
Self {
connect_url: database.connect_url,
torrent_info_update_interval: database.torrent_info_update_interval,
}
}
}
Expand Down Expand Up @@ -175,3 +181,11 @@ impl From<DomainApi> for Api {
}
}
}

impl From<DomainTrackerStatisticsImporter> for TrackerStatisticsImporter {
fn from(tracker_statistics_importer: DomainTrackerStatisticsImporter) -> Self {
Self {
torrent_info_update_interval: tracker_statistics_importer.torrent_info_update_interval,
}
}
}

0 comments on commit 57642ea

Please sign in to comment.