Skip to content

Commit

Permalink
feat: configurable refresh intervals (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanaden authored Jun 27, 2024
1 parent 96cc5ea commit 8cfd72f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion rm-config/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ url = "http://CHANGE_ME:9091/transmission/rpc" # REQUIRED!
# username = "CHANGE_ME"
# password = "CHANGE_ME"


# Refresh timings (in seconds)
torrents_refresh = 5
stats_refresh = 10
free_space_refresh = 10
6 changes: 6 additions & 0 deletions rm-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub struct Connection {
pub username: Option<String>,
pub password: Option<String>,
pub url: String,
#[serde(default)]
pub torrents_refresh: u64,
#[serde(default)]
pub stats_refresh: u64,
#[serde(default)]

This comment has been minimized.

Copy link
@micielski

micielski Jun 30, 2024

Contributor

BUT THE DEFAULT IS 0, THAT'S CRAZY FAST

pub free_space_refresh: u64,
}

const DEFAULT_CONFIG: &str = include_str!("../defaults/config.toml");
Expand Down
9 changes: 6 additions & 3 deletions rm-main/src/transmission/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn stats(ctx: app::Ctx, stats: Arc<Mutex<Option<SessionStats>>>) {
.arguments;
*stats.lock().unwrap() = Some(new_stats);
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_secs(ctx.config.connection.stats_refresh)).await;
}
}

Expand All @@ -50,7 +50,10 @@ pub async fn free_space(ctx: app::Ctx, free_space: Arc<Mutex<Option<FreeSpace>>>
.arguments;
*free_space.lock().unwrap() = Some(new_free_space);
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(10)).await;
tokio::time::sleep(Duration::from_secs(
ctx.config.connection.free_space_refresh,
))
.await;
}
}

Expand Down Expand Up @@ -85,6 +88,6 @@ pub async fn torrents(ctx: app::Ctx, table_manager: Arc<Mutex<TableManager>>) {
.set_new_rows(new_torrents.iter().map(RustmissionTorrent::from).collect());
}
ctx.send_action(Action::Render);
tokio::time::sleep(Duration::from_secs(5)).await;
tokio::time::sleep(Duration::from_secs(ctx.config.connection.torrents_refresh)).await;
}
}

0 comments on commit 8cfd72f

Please sign in to comment.