Skip to content

Commit

Permalink
fix: clean and format
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 19, 2023
1 parent cf9143d commit fc4424a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub struct Config {
long,
value_name = "MAX_STORAGE",
env = "MAX_STORAGE",
default_value = "3000",
default_value = "3000"
)]
pub max_storage: i32,
#[clap(
Expand Down
6 changes: 1 addition & 5 deletions src/db/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ RETURNING id, message as "message: Json<T>"
/// Function to automatically prune older messages and keep the `max_storage` newest messages
/// We prune from the smallest id by the automcatic ascending behavior
/// Return the number of messages deleted
pub async fn retain_max_storage(
pool: &PgPool,
max_storage: usize,
) -> Result<i64, anyhow::Error>
{
pub async fn retain_max_storage(pool: &PgPool, max_storage: usize) -> Result<i64, anyhow::Error> {
// find out the IDs of the top `max_storage` newest messages.
let top_ids: Vec<i64> = sqlx::query_as!(
MessageID,
Expand Down
3 changes: 1 addition & 2 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ pub static PRUNED_MESSAGES: Lazy<IntGauge> = Lazy::new(|| {
.subsystem("listener_radio"),
)
.expect("Failed to create pruned_messages gauge");
prometheus::register(Box::new(m.clone()))
.expect("Failed to register pruned_messages gauge");
prometheus::register(Box::new(m.clone())).expect("Failed to register pruned_messages gauge");
m
});

Expand Down
4 changes: 2 additions & 2 deletions src/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use graphcast_sdk::graphcast_agent::{
};

use crate::db::resolver::retain_max_storage;
use crate::metrics::{CONNECTED_PEERS, GOSSIP_PEERS, RECEIVED_MESSAGES, PRUNED_MESSAGES};
use crate::metrics::{CONNECTED_PEERS, GOSSIP_PEERS, PRUNED_MESSAGES, RECEIVED_MESSAGES};
use crate::{
config::Config,
db::resolver::{add_message, list_messages},
Expand Down Expand Up @@ -182,7 +182,7 @@ impl RadioOperator {
}

// Prune old messages
let num_pruned =
let num_pruned =
match timeout(update_timeout,
retain_max_storage(&self.db, self.config.max_storage.try_into().unwrap())
).await {
Expand Down

0 comments on commit fc4424a

Please sign in to comment.